Dynamic generate 8-Digit-Unicode to Character

*爱你&永不变心* 提交于 2021-02-08 05:16:38

问题


I am going to display Unicode dynamically,

For example, I know "\U00020001" will display a character. (variable "standard_format" below). However, I can only show the whole string directly ("\U00020001").

I would like to know how can I show that string into a character.

image reference


回答1:


If you write "\U0002B695" the whole string will be recognized as an escape sequence. In "\\U0002B695" however only \\ will be recognized as an escape sequence for \. I don't know a way to build a string literal this way and then parse it like the compiler would do.

In order to get the string you need to convert the hexadecimal value into an int and then convert that to a string:

string txt_unicodePoint = "2B695";

int value = int.Parse(txt_unicodePoint, System.Globalization.NumberStyles.HexNumber);
string result = char.ConvertFromUtf32(value).ToString();



回答2:


I belive what you want is Char.Parse(string s) http://msdn.microsoft.com/en-us/library/system.char.parse.aspx You'd pass it your escaped sequence "\U000..." string



来源:https://stackoverflow.com/questions/15990022/dynamic-generate-8-digit-unicode-to-character

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