Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Chr(0) in String

75 views
Skip to first unread message

Chris Wilmot

unread,
Aug 11, 2003, 1:32:22 PM8/11/03
to
I am trying to build up a string to sent through a socket.
Within this string Chr(0) appears to define the end of a field

Chr(3) Defines the username & chr(0) states the end of that field
Chr(4) Defines the Password & chr(0) states the end of that field
Chr(5) Defines the Software Version & chr(0) states the end of that field
The last 2 are single characters and do not need chr(0)
MyString=Chr(3) & config.Username & Chr(0) _

& Chr(4) & config.Password & Chr(0) _

& Chr(5) & config.Airpack_Login_Version & Chr(0) _

& Chr(25) & Chr(config.Receive) _

& Chr(26) & Chr(config.Transmit)

In VB6 this would create an appropriate String to be sent through the socket
but in Dot Net it gets to the first chr(0) then discards the rest.

Anyone have any advice on this one.

Thanks in advance

Chris Wilmot


Chris Dunaway

unread,
Aug 11, 2003, 3:20:22 PM8/11/03
to
"Chris Wilmot" <chris....@mtsgroup.co.uk> wrote in
news:#MXbR6CY...@TK2MSFTNGP12.phx.gbl:

How are you determining that the string is being truncated at the first
Chr$(0)? If you check the string length, does it also reflect a string
that has been truncated?

I tried the following code (I just substituted values because I didn't
know what your actual values were):

Private Sub Button2_Click(...) Handles Button2.Click

Dim sTest As String

sTest = VB.Chr(3) & "UserName" & VB.Chr(0) & _
VB.Chr(4) & "Password" & VB.Chr(0) & _
VB.Chr(5) & "LoginVersion" & VB.Chr(0) & _
VB.Chr(25) & VB.Chr(23) & _
VB.Chr(26) & VB.Chr(6)

'This MsgBox show the length of the string correctly
MsgBox(sTest.Length)

'These two lines display only up to the first Chr(0)
Debug.WriteLine("sTest is [" & sTest & "]")
MsgBox(sTest)

End Sub

The first message box show the correct string length of 38 characters.
But the Debug.WriteLine and the MsgBox truncate at the first zero byte.

Is the socket actually truncating the string or is a messagebox or
writeline doing it?

I suspect that your string is probably OK, just the display of it is
affected.

Hope this helps,

Chris
--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail

Herfried K. Wagner [MVP]

unread,
Aug 11, 2003, 4:27:47 PM8/11/03
to
Hello,

"Chris Wilmot" <chris....@mtsgroup.co.uk> schrieb:

Are you sure? Notice that some controls, the MsgBox function and the IDE
have problems displaying strings that contain a NullChar.

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Chris Wilmot

unread,
Aug 12, 2003, 3:56:01 AM8/12/03
to
Ok Built a VB6 App at the other end of the socket to test what is actually
being sent.

Even though VB.Net says I am sending nothing in the debug window after the
message is fully compiled it does actually send the relevant fields.

So if the debug window doesn't show the true condense of a string and when I
hover over the field that doesn't show it either then how am I suppose to
step through my application??

Chris Wilmot

"Chris Wilmot" <chris....@mtsgroup.co.uk> wrote in message
news:%23MXbR6C...@TK2MSFTNGP12.phx.gbl...

0 new messages