tags:

views:

247

answers:

1

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.

+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
pff. Thanks. Still thinking char is one byte... C detox...
Dervin Thunk
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
@Dervin: For characters not in the BMP, you need to use surrogate pairs.
Jon Skeet
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
Doh - hadn't noticed this was C# rather than Java. Editing my other answer...
Jon Skeet