I was wondering if it was possible, in a console application, to write characters like ?
using .NET. When I try to write this character, the console outputs a question mark.
This question is related to
c#
.net
vb.net
console-application
This works for me:
Console.OutputEncoding = System.Text.Encoding.Default;
To display some of the symbols, it's required to set Command Prompt's font to Lucida Console:
Open Command Prompt;
Right click on the top bar of the Command Prompt;
Click Properties;
If the font is set to Raster Fonts, change it to Lucida Console.
Besides Console.OutputEncoding = System.Text.Encoding.UTF8;
for some characters you need to install extra fonts (ie. Chinese).
In Windows 10 first go to Region & language settings and install support for required language:
After that you can go to Command Prompt Proporties (or Defaults if you like) and choose some font that supports your language (like KaiTi in Chinese case):
Console.OutputEncoding Property
https://docs.microsoft.com/en-us/dotnet/api/system.console.outputencoding
Note that successfully displaying Unicode characters to the console requires the following:
- The console must use a TrueType font, such as Lucida Console or Consolas, to display characters.
I found some elegant solution on MSDN
System.Console.Write('\uXXXX') //XXXX is hex Unicode for character
This simple program writes ? right on the screen.
using System;
public class Test
{
public static void Main()
{
Console.Write('\u2103'); //? character code
}
}
Source: Stackoverflow.com