Search code examples
c#inputconsole-applicationspecial-charactersconsole-input

<C#> The characters like "ä", "ö" or "å" drop out of the console input


I have a c# console application that needs input that contains characters like "ä", "ö" or "å". But these characters drop out of the input. For example if the user input is "abc äöå" it is delivered to the program as "abc " an anyone help?


Solution

  • You can change encoding as per below snippet code:

            Console.OutputEncoding = Console.InputEncoding = Encoding.Unicode;
            Console.Write("سلام بر برنامه نویس عزیز");
            string name = Console.ReadLine();
            Console.WriteLine($"اسم  {name}");
    

    And the output:

    Using Unicode in Console Window

    For more information check How to use character encoding classes in .NET