Windows Dev Center

Char.GetUnicodeCategory Method (String, Int32)

Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.

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

'Declaration
Public Shared Function GetUnicodeCategory ( _
	s As String, _
	index As Integer _
) As UnicodeCategory

Parameters

s
Type: System.String
A String.
index
Type: System.Int32
The character position in s.

Return Value

Type: System.Globalization.UnicodeCategory
A UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.

ExceptionCondition
ArgumentNullException

s is Nothing.

ArgumentOutOfRangeException

index is less than zero or greater than the last position in s.

Character positions in a string are indexed starting from zero.

The GetUnicodeCategory method does not always return the same UnicodeCategory value as the CharUnicodeInfo.GetUnicodeCategory(String, Int32) method when passed a particular character as a parameter. The CharUnicodeInfo.GetUnicodeCategory(String, Int32) method is designed to reflect the current version of the Unicode standard. In contrast, although the GetUnicodeCategory method usually reflects the current version of the Unicode standard, it may return a character's category based on a previous version of the standard or it may return a category that differs from the current standard in order to preserve backward compatibility. As a result, we recommend that you use the CharUnicodeInfo.GetUnicodeCategory(Char) method instead of Char.GetUnicodeCategory(String, Int32).

The following example demonstrates GetUnicodeCategory.



Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim ch2 As Char
      ch2 = "2"c
      Dim str As String
      str = "Upper Case"

      outputBlock.Text &= Char.GetUnicodeCategory("a"c) & vbCrLf   
      outputBlock.Text &= Char.GetUnicodeCategory(ch2) & vbCrLf       
      outputBlock.Text &= Char.GetUnicodeCategory(str, 6) & vbCrLf  
   End Sub
End Module
' The example displays the following output:
'       LowercaseLetter
'       DecimalDigitNumber
'       UppercaseLetter


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft