Reputation:
My application generate Persian text and show it in console window as unknown code! How can I have Unicode text in my application output in console? I used to below code but it doesn't work proper!
Console.InputEncoding = Encoding.UTF8;
Upvotes: 5
Views: 5753
Reputation: 354356
You should set your output encoding if you want output to appear correctly:
public class Test {
static void Main() {
System.Console.OutputEncoding = System.Text.Encoding.UTF8;
System.Console.WriteLine("پارسی");
}
}
works for me (and yes, even though the Windows console uses UTF-16 you have to set UTF-8; I have no idea why).
C:\>test.exe
پارسی
Note that the console may show ?????
in which case you need to set the console font to a TrueType font (e.g. Consolas or Lucida Console), otherwise the console tries converting everything into the OEM character set and characters that cannot be converted become question marks. After that the console shows still no Persian because there is no complex script rendering support, but you can copy/paste it just fine.
Upvotes: 7
Reputation: 483
As far as I know, Windows uses UCS-2 internally. Have you tried converting your text into this encoding?
Upvotes: -1