Convert Chinese Character to Unicode

Say I have a random Chinese character, 玩. I want to convert it to Unicode, which will be U + 73A9. How can I do this in C #?

+5
source share
3 answers

Take myChar as a char, referring to your special character ...

Console.WriteLine("{0} U+{1:x4} {2}", myChar, (int)myChar, (int)myChar);

Above, we print the character itself, followed by a Unicode code point, and then an integer value.

Reduce the format string and parameters to display only the code "U + ..." ...

Console.WriteLine("U+{0:x4}", (int)myChar);
+5
source

Syntax 玩 is in Unicode.

If you have C # as 玩, then it is currently in UTF-16, which is a form of Unicode encoding.

, :

  • , .
  • ( ).
  • .
  • , ( ).

3 (, !) (, !) - (, - ?!)

+2

, Jon Hanna:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnicodeDecodeConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            char c = '\u73a9';
            char[] chars = {c};
            Encoding encoding = Encoding.BigEndianUnicode;
            byte[] decodeds = encoding.GetBytes(chars);
            StringBuilder stringBuilder = new StringBuilder("U+");
            foreach (byte decoded in decodeds)
            {
                stringBuilder.Append(decoded.ToString("x2"));
            }
            Console.WriteLine(stringBuilder);
            Console.ReadLine();
        }
    }
}

-

0

All Articles