Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.Write() - display extended ascii chars?

I am able to correctly display the standard ASCII symbols (up to 127) like "heart", "note" you know what I mean. I would like to also display ones that I can use for drawing walls (like U0205) but it does not work..well, it works but it looks like "?". Any way how I can display them? Thank you.

like image 562
Loj Avatar asked Oct 16 '10 07:10

Loj


1 Answers

Console mode apps are restricted to an 8-bit code page encoding. The default on many machines is IBM437, the code page that matches the old IBM PC character set. You can change the code page by assigning the OutputEncoding property:

        Console.OutputEncoding = Encoding.UTF8;

But now you typically have a problem with the font. Consoles default to the Terminal font, an old device font that had glyphs in the right place to produce the IBM PC character set. There are not a lot of fonts available that can produce the proper glyphs that match the Unicode codepoints. Consolas is about it, available on Vista and Win7.

But that's not what you are asking, I think, I'm guessing that you are actually asking about the old box drawing characters. That works without any tinkering with the console settings, you just have to use the right Unicode characters. Here's an example that ought to survive a copy-and-paste:

class Program {
    static void Main(string[] args) {
        Console.WriteLine("╒════════╕");
        Console.WriteLine("│ Hello  │");
        Console.WriteLine("│ world  │");
        Console.WriteLine("╘════════╛");
        Console.ReadLine();
    }
}

To find these characters, use the Windows charmap.exe applet. Click the "Advanced view" checkbox and type "box" in the "Search for" text box, the grid will fill with the box drawing characters. The first usable one that will properly convert to the console is '\u250c'.

like image 59
Hans Passant Avatar answered Sep 22 '22 23:09

Hans Passant