I'm working on a project that involves Japanese text encoded in Shift-JIS. I'm trying to decode useful characters from arrays of bytes like so:
Encoding encoding = Encoding.GetEncoding(932);
string test = new string(encoding.GetChars(byteArray));
This works for 99% of the data but I'm getting weird results for just a handful of characters. The character '¨', for example. If I obtain the bytes corresponding to that character like this:
byte[] getBytesTest = encoding.GetBytes("¨");
The results are exactly what I expect. Two bytes, 0x81 and 0x4E, which is what that character is supposed to be in Shift-JIS.
If I try to convert it back to a string, though:
string getCharsTest = new string(encoding.GetChars(getBytesTest));
...I get the default error output "?".
So tl;dr, I'm trying to figure out why this:
byte[] getBytesTest = encoding.GetBytes("¨");
string getCharsTest = new string(encoding.GetChars(getBytesTest));
yields "?" instead of "¨" as a result.
What I have tried:
Passing the results of GetBytes() to GetChars() and manually passing the bytes in like this:
encoding.GetChars(new byte[] {0x81, 0x4E})
both fail to produce the expected result.
Not sure where to go with this.