bytes to string conversion

  • Thread starter Thread starter GM
  • Start date Start date
G

GM

Hello,

I have incoming bytes from a tcp connection.
These bytes contain characters like é,ç,à,...

When I convert these bytes into a string using
----
Dim clientdata As String = System.Text.Encoding.ASCII.getstring(bytes)
----
I loose my special characters.
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.

Any ideas?
 
GM,

Why not first start with "default" before you convert your input to 7bit
ASCII characters.

That will definitly remove all special characters.

Cor
 
Why not first start with "default" before you convert your input to 7bit
ASCII characters.

That will definitly remove all special characters.

Default also doesn't work (that was my first try)
 
----
I loose my special characters.
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.
good: Louie düvaliéè
bad: Louie dvali,S

The client is a c++ program, the server is vb.net
 
I've managed to achieve something like this as folows:

let's day I've got a byte-array with values: {200, 201, 202}, in chars: È,
É, Ê. If you try to convert it straightaway to a Unicode string it fails.
This is because Unicode uses 2 bytes for 1 character. So for each character
I've inserted a seccond byte with the value 0. You can easily achieve this
in a For...Next loop.

So now I've got a byte() with values: {200, 0, 201, 0, 202, 0}. If you
insert this array into the function:
System.Text.UnicodeEncoding.Unicode.GetString() it results in the correct
string.

HTH,
Friso Wiskerke
 
GM said:
I have incoming bytes from a tcp connection.
These bytes contain characters like é,ç,à,...

When I convert these bytes into a string using

ASCII is 7-bit only and does not contain these special characters
( said:
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.

What encoding is used to encode the data before sending? You'll have to use
the same encoding to decode the string from the byte array.
 
GM,

You can play a little with the different code tables, you can see what is
your computer in the language culture settings of that.

Than you can use a codeset
System.Text.Encoding.GetEncoding(437).GetBytes(Str.ReadToEnd)

This one is an old DOS one used in by instance the US, UK and NL.

The normal windows one is 1252

I hope this helps

Cor
 
Back
Top