visual-studio 在 Visual Studio、C# 中输入 Unicode 数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1239712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Entering Unicode data in Visual Studio, C#
提问by Adam Tegen
Is there a good way to type Unicode symbols in a C# file?
有没有一种在 C# 文件中键入 Unicode 符号的好方法?
I'm looking for something to the effect of:
我正在寻找具有以下效果的东西:
- Press ALT
- Type Unicode Hex
- Release Alt
- 按ALT
- 类型 Unicode 十六进制
- 释放 Alt
Currently, I'm having to type the symbol into word and copy-paste it into my source file.
目前,我必须将符号输入 word 并将其复制粘贴到我的源文件中。
采纳答案by Dykam
回答by Qny
The answer of Neutrinoactivated the Alt+Numpad input method (Microsoft Glossary), but I had to search for the correct registry path. It is:
Neutrino的回答激活了 Alt+Numpad 输入法(Microsoft Glossary),但我不得不搜索正确的注册表路径。它是:
- Navigate to HKCU\Control Panel\Input Method
- 导航到 HKC U\控制面板\输入法
I tried to write a Unicode-char within my comments in source (.
Unfortunately I cannot enter a Unicode code point, like shown in charmap, to get the corresponding character.
我试图在我的源代码 ( charmap.
- Using [Alt]+[+]+<xxxx>, where the hexadecimal Unicode code point (4-figure) replaces the xxxx, does not enter any character (neither [Numpad +] nor regular [+] key), when using the regularnumeric keys.
- Meanwhile using Numpadfor the 4-figured code (it has digits only), it is irrelevant to hit [+] before entering the Unicode code point. It just writes the same character like without preceding [+] (or in my case with preceding zero [0]). The entered character is the one defined in the codepage.
- Just for curiosity I have tried also using the decimal code (0x2192 = 8594) or switching the codepage via
chcp. But it does not change anything.
- 使用 [Alt]+[+]+<xxxx>,其中十六进制 Unicode 代码点(4 位数字)替换 xxxx,不输入任何字符(既不是 [Numpad +] 也不是常规的 [+] 键),当使用常规数字键。
- 同时使用Numpad作为 4 位数字的代码(它只有数字),在输入 Unicode 代码点之前按 [+] 无关紧要。它只是写出相同的字符,就像没有前面的 [+] (或者在我的情况下前面有零 [0])。输入的字符是代码页中定义的字符。
- 出于好奇,我也尝试过使用十进制代码 (0x2192 = 8594) 或通过
chcp. 但它不会改变任何东西。
Unluckily I find no way to convince Windows to enter the char with its U+xxxx code presented within Windows' own charmap.
Luckily, there people share this problem over multiple programs, not just Visual Studio. So the folks at http://www.fileformat.infoprovide several tipps in an article for Windows, among them a self written UnicodeInput Utilitywhich solves it.
Though I still think, Windows should have an built-in solution.
不幸的是,我找不到任何方法来说服 Windows 输入带有 Windows 自己的charmap. 幸运的是,人们通过多个程序共享这个问题,而不仅仅是 Visual Studio。因此,http://www.fileformat.info 上的人们在一篇针对 Windows 的文章中提供了几个技巧,其中包括一个解决此问题的自行编写的UnicodeInput 实用程序。
虽然我仍然认为,Windows 应该有一个内置的解决方案。
(PS: I would have added a comment, but my reputation is still too low.)
(PS:我本来想加评论的,但是我的名气还是太低了。)
回答by user4574
It appears that Visual Studio, by default, does not allow the use of many of the ALT codes. The work around is to just paste in the Unicode symbol.
1) run charmap.exe.
2) click advanced view.
3) search for the symbol you want (by name or code number).
4) copy the symbol you want.
5) paste it into your document.
charmap.exe comes standard with windows. You can use it to insert any Unicode symbol.
默认情况下,Visual Studio 似乎不允许使用许多 ALT 代码。解决方法是只粘贴 Unicode 符号。
1)运行charmap.exe。
2) 单击高级视图。
3) 搜索您想要的符号(按名称或代码编号)。
4)复制你想要的符号。
5) 将其粘贴到您的文档中。
Charmap.exe 是 Windows 的标准配置。您可以使用它来插入任何 Unicode 符号。
回答by Ludington
You can copy paste from the Unicode article on Wikipedia: http://en.wikipedia.org/wiki/List_of_Unicode_characters
您可以从维基百科上的 Unicode 文章中复制粘贴:http: //en.wikipedia.org/wiki/List_of_Unicode_characters
回答by Neutrino
I have to say that I don't think the selected answer actually answers the question at all. Entering the Unicode code point as a escape sequence in a string literal does not result in the Unicode symbol appearing in the file. Adding an escape sequence to a literal and typing the symbol are two different things.
我不得不说,我认为所选的答案根本没有回答问题。在字符串文字中输入 Unicode 代码点作为转义序列不会导致 Unicode 符号出现在文件中。将转义序列添加到文字和键入符号是两件不同的事情。
A better answer is:
更好的答案是:
- Open RegEdit
- Navigate to HKCR\Control Panel\Input Method
- Create string key EnableHexNumpad with value "1" (no quotes).
- Reboot.
- 打开注册编辑
- 导航至 HKCR\控制面板\输入法
- 创建值为“1”(无引号)的字符串键 EnableHexNumpad。
- 重启。
Now in any source file to type a Unicode symbol hold down ALT and type numpad plus followed by the hexadecimal code point then release ALT.
现在在任何源文件中键入一个 Unicode 符号,按住 ALT 并键入 numpad plus 后跟十六进制代码点,然后释放 ALT。
E.g. For ? hold ALT and enter +00a9.
例如对于?按住 ALT 并输入 +00a9。
Works in most windows apps, including Firefox :)
适用于大多数 Windows 应用程序,包括 Firefox :)
回答by Enrico
Just in case someone is looking how to do this in Linux, Ctrl+Shift+U, then type the code, and finally press Spaceor Enter, then the character will appear. Works with every application.
以防万一有人在 Linux 中寻找如何执行此操作,Ctrl+ Shift+ U,然后键入代码,最后按Space或Enter,然后字符将出现。适用于每个应用程序。

