Converting chinese character to Unicode

前端 未结 3 805
傲寒
傲寒 2020-12-17 04:20

Let\'s say I have a random Chinese character, 玩. I want to convert it to Unicode, which would be U+73A9. How could I do this in C#?

3条回答
  •  执念已碎
    2020-12-17 04:48

    The characater 玩 is in Unicode.

    If you have it in C# as 玩, then it's currently in UTF-16, which is one of the Unicode encoding forms.

    If you are obtaining it from somewhere else you need to:

    1. Find the encoding it is in.
    2. Get the bytes (wrapped by a stream is nice).
    3. Get of write an appropriate Encoder.
    4. Use the encoder to get the string (wrapping the nice stream with a textreader is nicer).

    Step 3 May be simple (oh, I just use that one!) or hard (darn, have to write it myself!) or somewhere in between (hey, anyone written one of these already?!)

提交回复
热议问题