I’m writing a program. Part of this program involves reading in a unicode value from an XML file and displaying the character on screen.
Now when I did it like this:
tbTester.Text = "\u597D";
It worked fine (tbTester is a Winforms text box). But with the other situation, basically I needed to alter a string to have the ‘\u’ and then the value. Like this:
szOut = szOut + "\u"+k.UnicodeID + " ";
For me, these don’t look all that different. Only now it tells me that the “\u” is an unrecognised escape sequence.
Now I did look this problem up and a double slash or the ‘@’ symbol does cure this particular situation, only now the text box contains ‘\u430B’ (or whatever) rather than the character which was output in the first of my examples.
When you compile code like your first example, the compiled CIL code doesn’t actually contain the escape sequence, but the character itself. And because
\uis invalid by itself, this causes the error you’re getting.If you have have Unicode code point as an integer, you can convert it into a character simply by casting. And the
+operator will take care of the rest:Although I tend to prefer
string.Format()in cases like this: