Dnx_7
asked on
Why String.length equals ZERO but the content equals ""
Hi,
I have a byte array and i get a string (unicode format)
the result is strange sometimes
the string length equals ZERO and the content of this string is empty...
can you explain me?
Regards
I have a byte array and i get a string (unicode format)
the result is strange sometimes
the string length equals ZERO and the content of this string is empty...
can you explain me?
Regards
ASKER
surely a termination character
i receive it from a socket (tcp listener) and it is a string
ReDim bytes(128) '
mySocket.Receive(bytes, bytes.Length, SocketFlags.None)
eventReceived = System.Text.Encoding.Unico de.GetStri ng(bytes)
i also have the problem to redim the byte array to exactly what i want to receive from the network...
Regards
i receive it from a socket (tcp listener) and it is a string
ReDim bytes(128) '
mySocket.Receive(bytes, bytes.Length, SocketFlags.None)
eventReceived = System.Text.Encoding.Unico
i also have the problem to redim the byte array to exactly what i want to receive from the network...
Regards
You have to trim the leading null characters:
Dim nulls As Char() = chr(0)
eventReceived = System.Text.Encoding.Unico de.GetStri ng(bytes). TrimEnd(nu lls)
Dim nulls As Char() = chr(0)
eventReceived = System.Text.Encoding.Unico
Sorry, I meant:
You have to trim the trailing null characters
You have to trim the trailing null characters
ASKER
eventReceived = System.Text.Encoding.Unico de.GetStri ng(bytes). TrimEnd(Co nvert.ToCh ar(10))
still have the same result... :(
the string is "bitlink 7" and the length equal 65
still have the same result... :(
the string is "bitlink 7" and the length equal 65
it is not char 10, it is char 0
ASKER
:(
event the 0 make the same result...
eventReceived = System.Text.Encoding.Unico de.GetStri ng(bytes). TrimEnd(Co nvert.ToCh ar(0))
regards...
event the 0 make the same result...
eventReceived = System.Text.Encoding.Unico
regards...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
IT WOOOORKKKKSSS!!!
Thank youuuu very much!
Kind regards
Thank youuuu very much!
Kind regards
Can you put up what is in your byte array and your code for changing it to a string?
Cheers,
Greg