如何使控制台可以打印任何的65535 UNICODE字符 [英] How to make console be able to print any of 65535 UNICODE characters

查看:299
本文介绍了如何使控制台可以打印任何的65535 UNICODE字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Unicode字符试验和维基百科

I am experimenting with unicode characters and taking unicode values from Wikipedia page

IHE问题是我的控制台显示所有的 C0控制和基本拉丁语 Unicode字符从U + 0000即U + 00FF但对于所有其他类别例如拉丁语扩展-B的,西里尔文,其他languges等,控制台打印问号字符()。

Ihe problem is my console displays all of C0 Controls and Basic Latin unicode characters ie from U+0000 to U+00FF but for all other categories like Latin Extended -B , Cyrillic , other languges etc , the console prints question mark character (?) .

我的C#代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataTypes
{
    class Program
    {
        static void Main(string[] args)
        {

            char ch = '\u0181';



            Console.WriteLine("the unicode character is  value" + ch);

        }
    }
}



我在Windows 7上工作时,Visual Studio 2010中我应该做的,以增加对Unicode的支持。

I am working on windows 7 , Visual studio 2010. What should i do to increase Unicode support.

推荐答案

有很多背后的历史的问题,我会先米线它一段时间。控制台模式的应用程序只能使用8位编码的文本操作。这又回到了一个设计决定做出42年前由Ken Thompson等人时,他们设计的Unix。的Unix的核心功能,终端I / O是通过管道完成,你可以链管一起,一个程序的输出输送到另一个输入。此功能也被在Windows中实现,是由.NET以及与ProcessStartInfo.RedirectStandardXxxx特性的支持。

There's a lot of history behind that question, I'll noodle about it for a while first. Console mode apps can only operate with an 8-bit text encoding. This goes back to a design decision made 42 years ago by Ken Thompson et al when they designed Unix. A core feature of Unix that terminal I/O was done through pipes and you could chain pipes together to feed the output of one program to the input of another. This feature was also implemented in Windows and is supported by .NET as well with the ProcessStartInfo.RedirectStandardXxxx properties.

不错的功能,但是这成为了一个问题,当操作系统开始采用Unicode格式。 Windows NT的是第一个,这是完全支持Unicode的核心。 Unicode字符必须始终进行编码,共同的选择当时是UCS,后来演变成UTF-16。现在,有一个与I / O重定向,即吐出16位编码的字符是不会运作良好时,它被重定向到一个仍然使用8位编码字符的程序的程序有问题。

Nice feature but that became a problem when operating systems started to adopt Unicode. Windows NT was the first one that was fully Unicode at its core. Unicode characters must always be encoded, a common choice back then was UCS, later morphed into utf-16. Now there's a problem with I/O redirection, a program that spits out 16-bit encoded characters is not going to operate well when it is redirected to a program that still uses 8-bit encoded characters.

信贷肯·汤普逊以及与找到该问题的解决方案,他发明了UTF-8编码。

Credit Ken Thompson as well with finding a solution for this problem, he invented utf-8 encoding.

这在Windows中也有效。易于在控制台模式的应用程序做,您必须将Console.OutputEncoding财产重新分配:

That works in Windows as well. Easy to do in a console mode app, you have to re-assign the Console.OutputEncoding property:

using System;
using System.Text;

class Program {
    static void Main(string[] args) {
        Console.OutputEncoding = Encoding.UTF8;
        Console.WriteLine("Ĥėļŀō ŵŏŗłđ");
        Console.ReadLine();
    }
}

您现在会遇到然而另一个问题,字体选择用于控制台窗口很可能是无法呈现文本。按Alt +空格键调用系统菜单,属性,字体选项卡。你需要选择一个非光栅字体。采摘非常渺茫,在Vista上最多可以选择索拉。重新运行您的程序和重音字符应正确显示。不幸的是,迫使控制台字体编程是个问题,您需要记录此配置步骤。此外,像索拉字体不具备全套的Unicode可能字形。你可能会看到矩形出现Unicode代码对于其没有字形。所有的那么直接的提醒,创造一个GUI程序真的是你最好的选择。

You'll now however encounter another problem, the font selected for the console window is likely to be unable to render the text. Press Alt+Space to invoke the system menu, Properties, Font tab. You'll need to pick a non-raster font. Pickings are very slim, on Vista and up you can choose Consolas. Re-run your program and the accented characters should render properly. Unfortunately, forcing the console font programmatically is a problem, you'll need to document this configuration step. In addition, a font like Consolas doesn't have the full set of possible Unicode glyphs. You are likely to see rectangles appear for Unicode codepoints for which it has no glyphs. All an unsubtle reminder that creating a GUI program is really your best bet.

这篇关于如何使控制台可以打印任何的65535 UNICODE字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆