From my previous question, Converting ch开发者_StackOverflowinese 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?
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.
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.
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)
http://msdn.microsoft.com/en-us/library/3hkfdkcx.aspx
精彩评论