0

I've write a code that Writes some special characters, but when I run it I get a lot of question marks (?) output

Here's the code:

        Console.WriteLine("");
        Console.Write(" ⌜ ", Color.FromArgb(51, 204, 255));
        Console.Write("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ ", Color.FromArgb(128, 128, 128));
        Console.Write("⌝", Color.FromArgb(51, 204, 255));
Mega
  • 55
  • 6
  • 1
    Try changing console font, e.g. `console.Font = new Font("Consolas", 12);` https://stackoverflow.com/questions/47014258/c-sharp-modify-console-font-font-size-at-runtime – Dmitry Bychenko Nov 20 '21 at 18:23
  • 1
    It doesn't seem that there is such thing as Console.Font – Mega Nov 20 '21 at 18:35
  • 1
    this may help https://stackoverflow.com/questions/2062875/show-utf-8-characters-in-console – Serg Nov 20 '21 at 18:42
  • Check that the source file is indeed in whichever encoding you consider default/normal/wanted. I usually open the file in Notepad to see which encoding is used. UTF-8 with BOM seems to be the default in VS. Also, console windows can show different encodings, so maybe you should figure out what that is too. And there is one more known problem. You can't be sure the character you see is encoded the way you think it is. It can vary depending on where you've copy-pasted it from. Turn the text into bytes, write out the value of the bytes, and see if they are what you expect. There may be surprises. – Bent Tranberg Nov 20 '21 at 19:08
  • Does it have to be a console app? – Caius Jard Nov 20 '21 at 19:44

2 Answers2

1

Output encoding could be ASCII.

You can try setting to UTF8 before Console.WriteLine

Console.OutputEncoding = System.Text.Encoding.UTF8;

Font could also be the issue, in some cases you need to install support for the required language, for example Korean. You can check this also on internet if changing the encoding doesn’t work for you.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • I tried that, it doesn't seem to change much, and I also gonna publish this app so I don't want my app to require extra languages to install and things like that – Mega Nov 20 '21 at 20:00
  • https://learn.microsoft.com/en-us/dotnet/api/system.console.outputencoding?view=net-6.0#notes-to-callers check this – Vivek Nuna Nov 20 '21 at 20:09
0

I think your best option might be to forget those old "extended" ASCII chars and use the Unicode equivalents. Here's an example that prints them:

Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.Write("     ");
for (int col = 0; col < 16; col++)
{
    Console.Write(" {0:X}", col);
}
Console.WriteLine();
for (int row = 0x2500; row <= 0x2570; row += 16)
{
    Console.Write("{0:X}", row);
    for (int col = 0; col < 16; col++)
    {
        Console.Write(" {0}", Char.ConvertFromUtf32(row + col));
    }
    Console.WriteLine("\r\n");
}

This outputs:

     0 1 2 3 4 5 6 7 8 9 A B C D E F
2500 ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏

2510 ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟

2520 ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯

2530 ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿

2540 ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏

2550 ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟

2560 ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯

2570 ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿

And here's a screenshot from my Windows 10 box: enter image description here

001
  • 13,291
  • 5
  • 35
  • 66