From my previous question, http://stackoverflow.com/questions/3571563/converting-chinese-character-to-unicode, I had a good answer but with some code I didn't understand:
Console.WriteLine("U+{0:x4}", (int)myChar);
Could anyone explain this?
From my previous question, http://stackoverflow.com/questions/3571563/converting-chinese-character-to-unicode, I had a good answer but with some code I didn't understand:
Console.WriteLine("U+{0:x4}", (int)myChar);
Could anyone explain this?
That will simply create the literal string "U+1234"... now if you are wanting to convert a unicode code point into a char, you want Convert.ToChar(myChar)
The 0
indicates which positional argument to substitute. The x
displays a hexadecimal number, the 4
has it display four digits.
For example, the character ȿ (LATIN SMALL LETTER S WITH SWASH TAIL, codepoint 575) is printed as U+023F
since 57510 = 23F16.
Console.WriteLine("U+{0:x4}", (int)myChar);
is the equivalent to the call:
Console.WriteLine("U+{0}", ((int)myChar).ToString("x4"));
In a format string, the :
indicates that the item should be displayed using the provided format. The x4
part indicates that the integer should be printed in its hexadecimal form using 4
characters. Refer to standard numeric format strings for more information.