3

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

apaderno
  • 28,547
  • 16
  • 75
  • 90
K.C
  • 287
  • 1
  • 2
  • 10

2 Answers2

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();
pescolino
  • 3,086
  • 2
  • 14
  • 24
  • that's cool. it works, do you know how to edit the html header to display that character normally? – K.C Apr 13 '13 at 17:50
  • @K.C: Maybe this helps: http://stackoverflow.com/questions/1696619/displaying-unicode-symbols-in-html – pescolino Apr 13 '13 at 17:59
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

djcrabhat
  • 464
  • 5
  • 10
  • i used string output2 = Char.Parse(output).ToString(); – K.C Apr 13 '13 at 16:55
  • but there are another error occur: String must be exactly one character long. – K.C Apr 13 '13 at 16:56
  • 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? – djcrabhat Apr 13 '13 at 17:02