BLOG.CSHARPHELPER.COM: Display special Unicode symbols in C#
Display special Unicode symbols in C#
Unicode (aka Unimess) lets you represent fonts that contain a large number of characters in more than one byte per symbol. For example, Chinese, Japanese, Cyrillic, and Arabic fonts use Unicode to display more than the 255 characters that can fit in simple ASCII codes.
Even those of us who don't typically deal with these fonts, Unicode characters can be handy. For example, Unicode can represent lots of special symbols such as ∞, ≈, and ∑.
There are several ways you can use Unicode in your programs. If you know a character's code, you can add it to character or string literals using an escape sequence of the form:
\u hex hex hex hex
As in the following code:
label1.Text = "\u0460";
You can also cast a numeric value into a Unicode character as in:
char ch = (char)0x460;
These methods are useful but you can also copy and paste Unicode characters directly into Visual Studio. Use Word, WordPad, or some other program to create the character you want. You can even select characters from a web page in your browser. Then copy and paste it into Visual Studio inside a character or string literal. You can even paste values into the Properties window to set a control's Text property at design time.
This example displays a Label and a TextBox that shows special symbols assigned at design time. It also uses the following code to generate more symbols at run time. (Note that the special symbols don't work well in web browsers so I've replaced them with ☐ symbols.)
Comments