-4

When I try to output unicode character 8595 (decimal), which is a down-arrow, from my C# command-line application, instead of seeing the down-arrow, the console displays a question mark in a box.

Is there a way to output the down-arrow character such that it displays in the console?

The only tool I have to code this with is visual studio. Below is my code:

    static void Main(string[] args)
    {
        char arrow = (char)8595;
        Console.WriteLine(arrow);
    }

Here is an image of what I see in the cmd.exe window when I run my command-line application (notice the boxed question mark above the letter 'P' in "Press"):

enter image description here

STLDev
  • 5,950
  • 25
  • 36
yonibros
  • 43
  • 5
  • 2
    You think your question is about VS. It isn't. It's about the *console*, which by default isn't Unicode aware. Using `unicode`, `console` and `.net` in a search engine is likely far more productive than this question. – Damien_The_Unbeliever Nov 05 '18 at 19:01
  • the ASCII codes for the arrows are 24, 25, 26, and 27 (↑ ↓ → ←). Your character index 8595 is far beyond the ASCII range (which is 0..255), and belongs to Unicode. – Cee McSharpface Nov 05 '18 at 19:05
  • 6
    Possible duplicate of [How to write Unicode characters to the console?](https://stackoverflow.com/questions/5750203/how-to-write-unicode-characters-to-the-console) – Derrick Moeller Nov 05 '18 at 19:06
  • Unicode character 8595 is indeed an arrow - a Unicode down-arrow: http://www.codetable.net/decimal/8595 – STLDev Nov 05 '18 at 19:08
  • Are you saying you are using [code page 20127](https://learn.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers)(ASCII) in your terminal? That would be highly unusual. (Go `chcp`) – Tom Blodget Nov 05 '18 at 20:35

2 Answers2

1

You need to let the console know that you're going to write non-ASCII characters to it.

Change your code as follows:

static void Main(string[] args)
{
    char arrow = (char)8595;

    Console.OutputEncoding = System.Text.Encoding.UTF8;  // set encoding of console
    Console.WriteLine(arrow);
}
STLDev
  • 5,950
  • 25
  • 36
0

I dont know if this will work but press alt + 'numpad' 26 then leave it, it should give you the arrow symbol then print that in the console

char arrow = '//Press Alt 26'; Console.WriteLine(arrow);