I have a function to convert a string to a Unicode string:
private string UnicodeString(string text) { return Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(text)); }
But when I am calling this function the output result is wrong. It looks like my function is not working.
Console.WriteLine(UnicodeString("добры дзень"))
printing on console just questions like that: ????? ????
Is there a way to say to console to display it correct?
UPDATE
It looks like the problem not in Unicode. I think maybe it is displaying question marks because I am not having the correct locale in the system (Windows 7)?
Is there a way to make it work without changing locale?
First, change the output encoding to UTF8:
Console.OutputEncoding = Encoding.UTF8; Console.WriteLine("добры дзень");
Now you'll still see question marks. The reason is that the default console's font doesn't support Cyrillic letters. Change the font of the console:
If you're lucky, you should find a different font with Unicode support:
Change the font, and you should be able to see your text:
In the general case, if you want to display all Unicode characters reliably, the Console is probably not right for you. See also: C# console font (the comments are interesting too)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With