Click to See Complete Forum and Search --> : Encoding problem


Jim Bassett
July 19th, 2005, 04:34 PM
The following simple code does not work(sY is empty). Does anyone have an idea why. This is using .NET 1.1

Encoding u8 = Encoding.UTF8;
string sX = "\x92"; // WORKS!
byte[] byteOne = new byte[1];
byteOne[0] = (byte)146;
string sY = u8.GetString(byteOne); // NOIE WORKIE!

sX works fine because it has the hex value in the string, but sY converting from the byte array doesn't (it's empty).

Norfy
July 20th, 2005, 01:52 AM
Just read MSDN, always a good idea... :) UTF-8 encodes Unicode characters with a variable number of bytes per character.string sX = "\x92"; // WORKS!
byte[] sxBytes = u8.GetBytes(sX); // byte[0] = 194 byte[1] = 146
sX == u8.GetString(sxBytes)