问题
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.
回答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