C#UNI code字符串输出 [英] c# unicode string output
问题描述
我有函数的字符串转换为统一code字符串:
I have function to convert 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(统一codeString的(добрыдзень))上的控制台
印刷只是问题这样的: ???? ? ????
Console.WriteLine(UnicodeString("добры дзень"))
printing on console just questions like that: ????? ????
有没有办法说安慰,以显示正确的吗?
Is there any way to say to console to display it correct?
更新
看起来问题不统一code,我觉得可能是显示问号,因为我没有在系统中(Windows 7)中正确的语言环境?
Looks like the problem not in Unicode, I think may be it is displaying question marks because i am not having correct locale in the system (Windows 7)?
有没有什么办法让它不改变语言环境工作?
Is there any way to make it work without changing locale?
推荐答案
首先,改变输出编码为UTF8:
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:
如果你幸运的话,你应该找一个不同的字体和UNI code支持:
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:
在一般情况下,如果要可靠地显示所有的Uni code字符,控制台可能不适合你。另请参阅: C#控制台字体(评论很有趣太)
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)
这篇关于C#UNI code字符串输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!