Decoding byte array to character

  • Thread starter Thread starter partysingh
  • Start date Start date
P

partysingh

Hi,

We have a legacy application sending data. It was written in C++ it
uses wcstombs to converting the data before sending.

When the data ia received in the dot net application using the
System.Net.Socket and when we try to get back the data using UTF8
decoder(System.Text.Encoding.UTF8.GetDecoder) the '£'(Ascii Value 163)
symbols are getting garbled up.

We have an old VB6 code it is using WinSock (with vbstring option) for
receiving the data. Its able to get the data fine.

Upon checking the received stream I have found that the data is coming
correctly i.e. I can see the byte data as 163(Ascii value for £). Upon
decoding to character array the issue is happening.

Let me know folks if you are aware how to fix it.

Thanks,
Mayank
 
partysingh said:
[...]
When the data ia received in the dot net application using the
System.Net.Socket and when we try to get back the data using UTF8
decoder(System.Text.Encoding.UTF8.GetDecoder) the '£'(Ascii Value 163)
symbols are getting garbled up. [...]

If your text is not actually UTF8, you should not be using the UTF8
decoder to decode the bytes.

However, note that the value 163 is not a valid ASCII value. More
likely, you actually should be using the ISO-8859-1 encoding for the
decoder.

Try Encoding.GetEncoding("ISO-8859-1").

Pete
 
We have a legacy application sending data. It was written in C++ it
uses wcstombs to converting the data before sending.


wcstombs uses the default system code page.
That is system dependent (so a Japanese system will be unable to
comunicate properly with an English one, unless the data is plain ASCII).
So it is very likely that the code page you have to use is cp1252
(not ISO-8859-1). They are close, but still not the same thing.
(cp1252 is a superset of ISO-8859-1)
 
Back
Top