user2330678
user2330678

Reputation: 2311

How to display (or write to file) Greek characters?

How to display (or write to file) Greek characters using C#? I need to type the Greek character epsilon in Excel using C#. The string to be written also has English characters. For example:

enter image description here

Upvotes: 11

Views: 27134

Answers (1)

Daniel A.A. Pelsmaeker
Daniel A.A. Pelsmaeker

Reputation: 50366

You can literally type the characters in your code. You can mix-and-match characters from any alphabet. So English and Greek characters in a single string is not a problem. If you don't know how to input them (e.g. if you don't have a Greek keyboard), then you can copy-and-paste them.

Console.Write("α");         // Greek lower-case alpha

Here is a list of lower-case and upper-case Greek characters for you to copy from:

α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω
Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω

If you're not using Visual Studio, you need to ensure that your text editor saves the code as Unicode (UTF-8).


Alternatively, you can use Unicode escape codes to write Greek characters.

Console.Write("\u03B1");    // Greek lower-case alpha

It is \u followed by the four-digit hexadecimal number of the character you want. You can find the hexadecimal values in this table. Simply ignore the &#x part.

Upvotes: 25

Related Questions