1

How can I display spacial codes in c# Console.WriteLine()?

Given: symbol = '\u2023'; The escape sequence \u2023 should display on console in c#. So, How can I get output for the symbol as '‣' and not '?'

What I get is just a wrong symbole '?' instead.

Wrong display of triangle bullet character in c# console

public void DisplayPattern (int n, char symbol)
{
    string pattern = "";
    for (int i = 0; i < num; i++)
    {
        pattern = new String(symbol, i);                  
        Console.WriteLine(pattern);
    }
}
fubo
  • 44,811
  • 17
  • 103
  • 137
Ali Safari
  • 1,535
  • 10
  • 19

2 Answers2

1

Set the console encoding

Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.Write('\u2023');

now it depends if you use a font that supports that character. Consolas doesn't.

fubo
  • 44,811
  • 17
  • 103
  • 137
0

So with help of you guys I write the answer down: As @fubo said: first add:

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

then choose an appropriate font like what @Crowcoder said: MS Gothic will turn all the question marks into triangle bullets.

Right display of symbols in c# console

Ali Safari
  • 1,535
  • 10
  • 19