Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CharUnicodeInfo Class

Retrieves information about a Unicode character. This class cannot be inherited.

System.Object
  System.Globalization.CharUnicodeInfo

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)
public static class CharUnicodeInfo
  NameDescription
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetNumericValue(Char)Gets the numeric value associated with the specified character.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetNumericValue(String, Int32)Gets the numeric value associated with the character at the specified index of the specified string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetUnicodeCategory(Char)Gets the Unicode category of the specified character.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetUnicodeCategory(String, Int32)Gets the Unicode category of the character at the specified index of the specified string.
Top

The Unicode Standard defines several properties for Unicode characters, one of which is the character's category. For example, a character might be categorized as an uppercase letter, a lowercase letter, a decimal digit number, a letter number, a connector punctuation, a math symbol, or a currency symbol. Your application can use the character's category to govern string-based operations such as parsing.

The UnicodeCategory enumeration defines categories for Unicode characters. The CharUnicodeInfo class is used to obtain the UnicodeCategory value for a specific character. In addition, the class provides information about the numeric value of Unicode characters. A character's numeric value applies only to numeric characters, which include fractions, subscripts, superscripts, Roman numerals, currency numerators, encircled numbers, and script-specific digits.

For more information on Unicode characters, see the Unicode Standard.

The following code example shows the values returned by each method for different types of characters.


using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "                                        c  Num   Dig   Dec   UnicodeCategory" + "\n";

      outputBlock.Text += "U+0061 LATIN SMALL LETTER A            ";
      PrintProperties(outputBlock, 'a');

      outputBlock.Text += "U+0393 GREEK CAPITAL LETTER GAMMA      ";
      PrintProperties(outputBlock, '\u0393');

      outputBlock.Text += "U+0039 DIGIT NINE                      ";
      PrintProperties(outputBlock, '9');

      outputBlock.Text += "U+00B2 SUPERSCRIPT TWO                 ";
      PrintProperties(outputBlock, '\u00B2');

      outputBlock.Text += "U+00BC VULGAR FRACTION ONE QUARTER     ";
      PrintProperties(outputBlock, '\u00BC');

      outputBlock.Text += "U+0BEF TAMIL DIGIT NINE                ";
      PrintProperties(outputBlock, '\u0BEF');

      outputBlock.Text += "U+0BF0 TAMIL NUMBER TEN                ";
      PrintProperties(outputBlock, '\u0BF0');

      outputBlock.Text += "U+0F33 TIBETAN DIGIT HALF ZERO         ";
      PrintProperties(outputBlock, '\u0F33');

      outputBlock.Text += "U+2788 CIRCLED SANS-SERIF DIGIT NINE   ";
      PrintProperties(outputBlock, '\u2788');
   }

   public static void PrintProperties(System.Windows.Controls.TextBlock outputBlock, char c)
   {
      outputBlock.Text += String.Format(" {0,-3}", c);
      outputBlock.Text += String.Format(" {0,-5}", CharUnicodeInfo.GetNumericValue(c));
      outputBlock.Text += String.Format("{0}", CharUnicodeInfo.GetUnicodeCategory(c)) + "\n";
   }
}
/*
This example produces the following output. 
   U+0061 LATIN SMALL LETTER A             a   -1   LowercaseLetter
   U+0393 GREEK CAPITAL LETTER GAMMA       G   -1   UppercaseLetter
   U+0039 DIGIT NINE                       9   9    DecimalDigitNumber
   U+00B2 SUPERSCRIPT TWO                  ²   2    OtherNumber
   U+00BC VULGAR FRACTION ONE QUARTER      ¼   0.25 OtherNumber
   U+0BEF TAMIL DIGIT NINE                 ?  9    DecimalDigitNumber
   U+0BF0 TAMIL NUMBER TEN                 ?   10   OtherNumber
   U+0F33 TIBETAN DIGIT HALF ZERO          ? -0.5   OtherNumber
   U+2788 CIRCLED SANS-SERIF DIGIT NINE    ?    9   OtherNumber
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.