Hello, apologies if this is silly. How do I print a Unicode character, say \u20ac using an integer? So, instead of Console.WriteLine("\u20ac");
, I would like to pass the integer 8364.
Thanks.
views:
247answers:
1
+3
A:
Just cast the number to char
which represents a UTF-16 code point:
public static void PrintChar(int codePoint)
{
Console.WriteLine((char) codePoint);
}
PrintChar(8364);
Jon Skeet
2009-09-14 21:42:09
pff. Thanks. Still thinking char is one byte... C detox...
Dervin Thunk
2009-09-14 21:44:06
However, just looked at the definition of char and it goes up to ffff, how do you do the same for astral planes?
Dervin Thunk
2009-09-14 21:45:05
@Dervin: For characters not in the BMP, you need to use surrogate pairs.
Jon Skeet
2009-09-14 21:54:31
right, that's what I'm doing (from scratch, I'm not using any functions from .net). That's why, suppose I do get the right integer, , how do I write that to to stdout (doesn't matter that the glyph is not available)?
Dervin Thunk
2009-09-14 21:59:26
Doh - hadn't noticed this was C# rather than Java. Editing my other answer...
Jon Skeet
2009-09-14 22:37:54