2

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

2 Answers 2

5

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(); 
Sign up to request clarification or add additional context in comments.

2 Comments

that's cool. it works, do you know how to edit the html header to display that character normally?
0

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

3 Comments

i used string output2 = Char.Parse(output).ToString();
but there are another error occur: String must be exactly one character long.
that is very true. If you're trying to pull out these escape sequences from an existing string, you'd have to regex match for them and parse individually. what is the purpose of this? this there's some "compose" section of a form where people can type these sequences, and you want to show the encoded string?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.