Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get unicode encoding string

Status
Not open for further replies.

Dnx07

Programmer
Oct 1, 2008
6
BE
Hi experts,

i use socket to receive string in unicode format
it works, i can receive and decode text using this :

ReDim bytes(128)
bytesReceived = mySocket.Receive(bytes, bytes.Length, SocketFlags.None)

eventReceived = System.Text.Encoding.Unicode.GetString(bytes, 0, bytesReceived).TrimEnd(Convert.ToChar(0))
eventReceived = eventReceived.Trim


but the problem is :
when i read the "EventReceived" and after trimming i got (e.g.) :

"test 1"

but when i'm checking the length, the string has a value of 100 character!!!

how can i cleanup the string?

Regards
 
String :(

i reduced the byte array from 128 to 20 and it seems to be more stable but sometimes i still have string garbage :(

regards
 
sorry, i was mistaken, i reduced from 128 to 64 and not 20.
 
Are you sure you're trimming the correct character when you call your TrimEnd?
 
the problem is that i don't know wich is the character ends the string.

regards
 
Code:
Dim c As Char = eventReceived .Substring(eventReceived .Length - 1, 1)
eventReceived = eventReceived.TrimEnd(c)
 
I found the character that end the string
it's the ascii code 0 or 655533

that is weird...

sometimes there is still some garbage but less than before.

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top