CharUnicodeInfo.GetUnicodeCategory Method (Char)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the Unicode category of the specified character.

Namespace:   System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function GetUnicodeCategory (
	ch As Char
) As UnicodeCategory


Type: System.Char

The Unicode character for which to get the Unicode category.

Return Value

Type: System.Globalization.UnicodeCategory

A UnicodeCategory value indicating the category of the specified character.

The Unicode characters are divided into categories. A character's category is one of its properties. For example, a character might be an uppercase letter, a lowercase letter, a decimal digit number, a letter number, a connector punctuation, a math symbol, or a currency symbol. The UnicodeCategory class returns the category of a Unicode character. For more information on Unicode characters, see the Unicode Standard.

The GetUnicodeCategory method assumes that ch corresponds to a single linguistic character and returns its category. This means that, for surrogate pairs, it returns UnicodeCategory.Surrogate instead of the category to which the surrogate belongs. For example, the Ugaritic alphabet occupies code points U+10380 to U+1039F. The following example uses the ConvertFromUtf32 method to instantiate a string that represents UGARITIC LETTER ALPA (U+10380), which is the first letter of the Ugaritic alphabet. As the output from the example shows, the IsNumber(Char) method returns false if it is passed either the high surrogate or the low surrogate of this character.

Dim utf32 As Integer = &h10380       ' UGARITIC LETTER ALPA
Dim surrogate As String = Char.ConvertFromUtf32(utf32)
For Each ch In surrogate
   Console.WriteLine("U+{0:X4}: {1:G}", 
' The example displays the following output:
'       U+D800: Surrogate
'       U+DF80: Surrogate

Note that CharUnicodeInfo.GetUnicodeCategory does not always return the same UnicodeCategory value as the Char.GetUnicodeCategory method when passed a particular character as a parameter. The CharUnicodeInfo.GetUnicodeCategory method is designed to reflect the current version of the Unicode standard. In contrast, although the Char.GetUnicodeCategory method usually reflects the current version of the Unicode standard, it might return a character's category based on a previous version of the standard, or it might return a category that differs from the current standard to preserve backward compatibility.

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

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesCharUnicodeInfo   

   Public Shared Sub Main()

      Console.WriteLine("                                        c  Num   Dig   Dec   UnicodeCategory")

      Console.Write("U+0061 LATIN SMALL LETTER A            ")

      Console.Write("U+0393 GREEK CAPITAL LETTER GAMMA      ")

      Console.Write("U+0039 DIGIT NINE                      ")

      Console.Write("U+00B2 SUPERSCRIPT TWO                 ")

      Console.Write("U+00BC VULGAR FRACTION ONE QUARTER     ")

      Console.Write("U+0BEF TAMIL DIGIT NINE                ")

      Console.Write("U+0BF0 TAMIL NUMBER TEN                ")

      Console.Write("U+0F33 TIBETAN DIGIT HALF ZERO         ")

      Console.Write("U+2788 CIRCLED SANS-SERIF DIGIT NINE   ")

   End Sub 'Main

   Public Shared Sub PrintProperties(c As Char)
      Console.Write(" {0,-3}", c)
      Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(c))
      Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(c))
      Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(c))
      Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(c))
   End Sub 'PrintProperties

End Class 'SamplesCharUnicodeInfo 

'This code produces the following output.  Some characters might not display at the console.
'                                        c  Num   Dig   Dec   UnicodeCategory
'U+0061 LATIN SMALL LETTER A             a   -1    -1    -1   LowercaseLetter
'U+0393 GREEK CAPITAL LETTER GAMMA       \u0393   -1    -1    -1   UppercaseLetter
'U+0039 DIGIT NINE                       9   9     9     9    DecimalDigitNumber
'U+00B2 SUPERSCRIPT TWO                  \u00B2   2     2     2    OtherNumber
'U+00BC VULGAR FRACTION ONE QUARTER      \u00BC   0.25  -1    -1   OtherNumber
'U+0BEF TAMIL DIGIT NINE                 \u0BEF   9     9     9    DecimalDigitNumber
'U+0BF0 TAMIL NUMBER TEN                 \u0BF0   10    -1    -1   OtherNumber
'U+0F33 TIBETAN DIGIT HALF ZERO          \u0F33   -0.5  -1    -1   OtherNumber
'U+2788 CIRCLED SANS-SERIF DIGIT NINE    \u2788   9     9     -1   OtherNumber

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top