Entering Unicode data in Visual Studio, C#

感情迁移 提交于 2020-07-20 07:14:08

问题


Is there a good way to type Unicode symbols in a C# file?

I'm looking for something to the effect of:

  1. Press ALT
  2. Type Unicode Hex
  3. Release Alt

Currently, I'm having to type the symbol into word and copy-paste it into my source file.


回答1:


\uFFFF
\UFFFFFFFF

C# Unicode character escape sequences.




回答2:


The answer of Neutrino activated the Alt+Numpad input method (Microsoft Glossary), but I had to search for the correct registry path. It is:

  1. Navigate to HKCU\Control Panel\Input Method

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.

  • 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 regular numeric keys.
  • Meanwhile using Numpad for 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.

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.info provide several tipps in an article for Windows, among them a self written UnicodeInput Utility which solves it.
Though I still think, Windows should have an built-in solution.

(PS: I would have added a comment, but my reputation is still too low.)




回答3:


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.




回答4:


You can copy paste from the Unicode article on Wikipedia: http://en.wikipedia.org/wiki/List_of_Unicode_characters




回答5:


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.

A better answer is:

  1. Open RegEdit
  2. Navigate to HKCR\Control Panel\Input Method
  3. Create string key EnableHexNumpad with value "1" (no quotes).
  4. Reboot.

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.

E.g. For © hold ALT and enter +00a9.

Works in most windows apps, including Firefox :)




回答6:


Just in case someone is looking how to do this in Linux, Ctrl+Shift+U, then type the code, and finally press Space or Enter, then the character will appear. Works with every application.



来源:https://stackoverflow.com/questions/1239712/entering-unicode-data-in-visual-studio-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!