Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write special characters (0x80..0x9F) to the Windows console?

I would like to have this code:

System.Console.Out.WriteLine ("œil");

display œil instead of oil as it does in my test program.

The Console.OutputEncoding is set by default to Western European (DOS) (CodePage set to 850 and WindowsCodePage set to 1252) on my system. The character set contains the special OE and oe diphtongs (as can be seen on the Wikipedia article on Windows-1252) but somehow, I suspect that the characters not found in the ISO-8859-1 set get discarded/replaced.

Characters such as â, ç, etc. get properly displayed on the console, but any character in the extended 0x80 ... 0x9F range are not.

How can I properly display them on the console?

like image 890
Pierre Arnaud Avatar asked Oct 28 '11 13:10

Pierre Arnaud


2 Answers

Like this:

Console.OutputEncoding = System.Text.Encoding.UTF8;
System.Console.Out.WriteLine("œil");

Don't forget to select a font for your console window that supports the characters you need. This is a screen shot of my console window using the Consolas font.

enter image description here

like image 168
David Heffernan Avatar answered Nov 14 '22 21:11

David Heffernan


You could set the output encoding on the console like this...

Console.OutputEncoding = Encoding.UTF8;
like image 27
Prashanth Avatar answered Nov 14 '22 22:11

Prashanth