Question

I have a unicode string, let's say "U+660E", and I want to display the corresponding character, which in this case is 明. See this page (ctrl-F to find 明).

My code so far:

string unicodeString = reader.GetString(0);
unicodeString.Trim();

Encoding codepage = Encoding.GetEncoding(950);
Encoding unicode = Encoding.Unicode;
byte[] encodedBytes = codepage.GetBytes(unicodeString);
//unicodeString = Encoding.Convert(codepage, unicode, encodedBytes).ToString();
unicodeString = unicode.GetString(encodedBytes);
richTextBox1.Text = unicodeString;

My output is "⭕㘶䔰�". Any idea where I went wrong?

Was it helpful?

Solution

.net deals directly with unicode. You do not have to play the encoding games. Just tell the reader if the input is UTF-8 or UTF-16 and then deal with it as a normal string.

richTextBox1.Text = reader.GetString(0)

OTHER TIPS

There's no need to convert to CP-950; C# is Unicode through-and-through. Just input and print as Unicode unless you're outputting to a file that you know has to be CP-950.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top