Wednesday, March 28, 2012

String.Length issue

Hi. I've got a vb.net/asp.net application that passes strings back a
forth between a c++ COM object. We use simple tagging to designate
what's what, and it's worked pretty well until now. We had some data
that wasn't parsing right because it also contained tags that conflicted
with the tags designating the data.
To get around this the programmer of the COM object (not me) decided we
could put string lengths in the tags, so if an element was called x, I'd
send <x L=3>123</x> with the L= indicating the length of the string. So
I wrote a tagging function to take care of this that uses the
String.Length property to calculate the length of the string. Then I
send the following string, and he can't parse it out:
<body L=579>Dear MATT B--
Thanks for purchasing Print@dotnet.itags.org.Home tickets!
Included in this this email is a link to your ticket(s) from sale id
**SUB(wwsale_id).
To retrieve your tickets, please click (or copy/paste into your browser)
the link below:
<http://localhost/webwaresales1/GetT...//www.adobe.com)
to view or print your items.
You will need to bring your printed tickets with you to the resort.
Thanks again and we look forward to seeing you soon!
S--, Inc.</body>
The other guy said he calculates a length of 551 but if I use
String.Length I get 579. Incidentally, if I paste the string into
TextPad and look at the document properties, it says 551 characters and
a file size of 579.
So can anyone explain where the difference (28) comes from? It's not the
number of lines (15) and I don't see any other special characters
besides line endings.
Thanks!
MattMattB <somedudeus@.yahoo.com> wrote in news:3n41c6F19h9o1U3@.individual.net:

> The other guy said he calculates a length of 551 but if I use
> String.Length I get 579. Incidentally, if I paste the string into
> TextPad and look at the document properties, it says 551 characters and
> a file size of 579.
> So can anyone explain where the difference (28) comes from? It's not the
> number of lines (15) and I don't see any other special characters
> besides line endings.
Line endings actually take up 2 bytes in Windows. Carriage Return and Line
Feed.
So 579 bytes is correct - there are 15 lines, but only 14 CR + LF. So:
551 bytes + (14 CRLF x 2 bytes) = 579 : )
BTW, didn't the other guy calculate 579 too? (<body L=579> ).
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]

0 comments:

Post a Comment