bytes to string conversion

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?
 
C

Cor Ligthert

GM,

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

That will definitly remove all special characters.

Cor
 
G

GM

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)
 
G

GM

----
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
 
F

Friso Wiskerke

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
 
H

Herfried K. Wagner [MVP]

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.
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top