Show UTF-8 characters in console
How can I pri开发者_开发技巧nt UTF8 characters in the console?
With Console.Writeline("îăşâţ")
I see îasât
in console.
Console.OutputEncoding = Encoding.UTF8;
There are some hacks you can find that demonstrate how to write multibyte character sets to the Console, but they are unreliable. They require your console font to be one that supports it, and in general, are something I would avoid. (All of these techniques break if your user doesn't do extra work on their part... so they are not reliable.)
If you need to write Unicode output, I highly recommend making a GUI application to handle this, instead of using the Console. It's fairly easy to make a simple GUI to just write your output to a control which supports Unicode.
Try this :
using System.Diagnostics
...
Debug.WriteLine(..);// will output utf-8 charset
Using Console.OutputEncoding will be sufficient for this. All string objects in .NET are by default unicode so changing output encoding for console to UTF-8 will work as you want in modern Windows installations.
Default encoding in console depends on configuration but it will be most likely IBM437 for US language or some local codepage.
You can't print Unicode characters in the console, it only supports the characters that are available in the current code page. Characters that are not available are converted to the closest equivalent, or a question mark.
精彩评论