Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

February 22, 2010

Setting a Char Value to a Symbol

Filed under: C#,VB.NET @ 3:15 pm

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!

1 Comment

  1.   Thomas Andersson — July 30, 2010 @ 5:10 am    Reply

    Thanks a lot for a great example :-)

RSS feed for comments on this post. TrackBack URI

Leave a comment

*

© 2014 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs