user2970331
user2970331

Reputation: 31

How to output greek symbols in c# Console Application?

I'm trying to output θ (theta) on a console applicatation and I searched on Google and found that I have to use Unicode to output any greek symbols. So the code I used was:

Console.WriteLine("\u03B8 (deg)  R (m) \t T (kN)  FOS");

But instead of printing 'θ', '?' is printed. Can somebody advise me please?

Upvotes: 3

Views: 3444

Answers (2)

Aniket Inge
Aniket Inge

Reputation: 25705

See How to make Unicode charset in cmd.exe by default?

The answers to this question explain how to set up cmd.exe to display Unicode characters.

Specifically, this answer suggests changing the registry:

  1. Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
  2. Change the OEMCP value to 65001

Upvotes: 2

Reacher Gilt
Reacher Gilt

Reputation: 1813

If you're outputting to the console, you'll have to change your codepage to something that understands unicode. You can do this by typing chcp 65001 at a command prompt. You'll also have to change your font to Lucida Console or Consolas:

enter image description here

Edit: Well of course it's possible to do in C# as well:

    public static void Main()
    { 
        Console.OutputEncoding = System.Text.Encoding.Unicode;
        Console.WriteLine("\u03B8");
        Console.ReadLine();
    }

I think you'll still have to massage the font by hand (or by unmanaged code).

Upvotes: 4

Related Questions