Console.Write() - 显示扩展 ascii 字符?
我能够正确显示标准 ASCII 符号(最多 127 个),例如“heart”、“note”,你知道我的意思。我还想展示那些可以用来画墙的东西(比如 U0205),但它不起作用……好吧,它起作用,但它看起来像“?”。我有什么办法可以显示它们吗?谢谢。
I am able to correctly display the standard ASCII symbols (up to 127) like "heart", "note" you know what I mean. I would like to also display ones that I can use for drawing walls (like U0205) but it does not work..well, it works but it looks like "?". Any way how I can display them? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
控制台模式应用程序仅限于 8 位代码页编码。许多机器上的默认值是 IBM437,该代码页与旧的 IBM PC 字符集相匹配。您可以通过分配 OutputEncoding 属性来更改代码页:
但现在您通常会遇到字体问题。控制台默认使用终端字体,这是一种旧的设备字体,其字形位于正确的位置以生成 IBM PC 字符集。没有很多可用的字体可以生成与 Unicode 代码点匹配的正确字形。 Consolas 就是这样,可在 Vista 和 Win7 上使用。
但这不是你要问的,我想,我猜你实际上是在问旧的盒子画角色。无需对控制台设置进行任何修改即可工作,您只需使用正确的 Unicode 字符即可。下面是一个复制粘贴后仍能保存的示例:
要查找这些字符,请使用 Windows charmap.exe 小程序。单击“高级视图”复选框并在“搜索”文本框中键入“box”,网格将填充方框绘图字符。第一个可以正确转换到控制台的可用的是“\u250c”。
Console mode apps are restricted to an 8-bit code page encoding. The default on many machines is IBM437, the code page that matches the old IBM PC character set. You can change the code page by assigning the OutputEncoding property:
But now you typically have a problem with the font. Consoles default to the Terminal font, an old device font that had glyphs in the right place to produce the IBM PC character set. There are not a lot of fonts available that can produce the proper glyphs that match the Unicode codepoints. Consolas is about it, available on Vista and Win7.
But that's not what you are asking, I think, I'm guessing that you are actually asking about the old box drawing characters. That works without any tinkering with the console settings, you just have to use the right Unicode characters. Here's an example that ought to survive a copy-and-paste:
To find these characters, use the Windows charmap.exe applet. Click the "Advanced view" checkbox and type "box" in the "Search for" text box, the grid will fill with the box drawing characters. The first usable one that will properly convert to the console is '\u250c'.
问题似乎出在控制台应用程序而不是您的程序上。 Windows 中的标准控制台 (cmd.exe) 似乎无法正确支持 Unicode - 例如,尝试复制下面的字符串并直接粘贴到 cmd.exe 窗口中:
PowerShell 似乎也遇到了同样的问题。
解决您的问题的一种可能的解决方案是创建一个专用窗口/窗体用作“输出控制台”,而不是使用执行应用程序的实际控制台。
The problem appears to be with the Console application rather than with your program. The standard console in windows (cmd.exe) appears not to support Unicode properly - for example, try copying the string below and pasting directly into a cmd.exe window:
PowerShell seems to suffer from the same problem as well.
One possible solution to your problem is to create a dedicated window/form to be used as an "output console" instead of using the actual console through which the application was executed.