Setting a Char Value to a Symbol

Posted Mon, Feb 22 2010 13:15 by Deborah Kurata

This prior post demonstrated how to set char values in VB and C#. But what if you want to display a special character, like a degree symbol?

The following code displays a heart and a degree symbol.

In C#:

// Heart
TextBox1.Font = new Font("Arial Unicode MS", 12, FontStyle.Regular);
TextBox1.Text = '\u2764'.ToString();

// Degree symbol
TextBox1.Text += "45" + '\u00B0'.ToString();

In VB:

' Heart
TextBox1.Font = New Font("Arial Unicode MS", 12, FontStyle.Regular)
TextBox1.Text = ChrW(&H2764)

' Degree symbol
TextBox1.Text &= "45" & ChrW(&HB0)
' OR
TextBox1.Text &= "45" & Chr(176)

The key here is to set an appropriate font that contains the desired symbol. Then use the Unicode or ASII value to access the specific symbol.

The result is:

image

To view a Unicode character map, use this link.

Enjoy!

Filed under: , , ,

Comments

# Linked - List

Tuesday, February 23, 2010 1:35 PM by ASeventhSign

Linked - List

# re: Setting a Char Value to a Symbol

Friday, July 30, 2010 5:10 AM by Thomas Andersson

Thanks a lot for a great example :-)

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: