settingsAccountsettings
Menusettings

Q: Printing special characters (Cyrillic) in the console in C#?

+3 votes

How can I print special characters (Cyrillic for example) on the console in Visual Basics (C#)?

For a particular task for Visual Studio, I need to print the whole cyrillic alphabet.

However, I only see question marks instead of the cyrillic letters. How can I change Visual Basics so it shows them?

cannot see cyrillic in visual basics in c sharp

asked in C# category by user Jolie Ann
edited by user golearnweb

2 Answers

+2 votes
 
Best answer

You can print special characters on the console in two easy steps:

1. Change the console properties with a right-click on the Console (You can change the Defaults as well) to enable Unicode-friendly font (the default is Raster Fonts):

change the font in Visual Studio

2. Enable Unicode for the Console by adjusting its output encoding Prefer UTF8 (Unicode):

Console.OutputEncoding = Encoding.UTF8;


Here is the whole cyrillic alphabet:

using System;
using System.Text;

class Alphabet
{
    static void Main()
    {
        Console.OutputEncoding = Encoding.UTF8;
        char a1 = 'А';
        char a2 = 'Б';
        char a3 = 'В';
        char a4 = 'Г';
        char a5 = 'Д';
        char a6 = 'Е';
        char a7 = 'Ё';
        char a8 = 'Ж';
        char a9 = 'З';
        char a10 = 'И';
        char a11 = 'Й';
        char a12 = 'К';
        char a13 = 'Л';
        char a14 = 'М';
        char a15 = 'Н';
        char a16 = 'О';
        char a17 = 'П';
        char a18 = 'Р';
        char a19 = 'С';
        char a20 = 'Т';
        char a21 = 'У';
        char a22 = 'Ф';
        char a23 = 'Х';
        char a24 = 'Ц';
        char a25 = 'Ч';
        char a26 = 'Ш';
        char a27 = 'Щ';
        char a28 = 'Ъ';
        char a29 = 'Ы';
        char a30 = 'Ь';
        char a31 = 'Э';
        char a32 = 'Ю';
        char a33 = 'Я';
        Console.WriteLine("Cyrillic Alpahbet: {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}", a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33);
    }
}

OUTPUT:

printing the whole cyrillic alphabet in Visual Studio

 

 

answered by user john7
edited by user golearnweb
+1 vote

You can also add this:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

or

Thread.CurrentThread.CurrentCulture = new CultureInfo(ru-RU);

before

Console.OutputEncoding = Encoding.UTF8;

answered by user paulcabalit
edited by user golearnweb
Thank You so much. About half the Answers on the Web made no sense.
You really simplified it with this snippet.
Thanks again. And than just about any other Language Correct?
...