Char.GetUnicodeCategory Method (Char)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Updated: December 2010
Categorizes a specified Unicode character into a group identified by one of the UnicodeCategory values.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Shared Function GetUnicodeCategory ( _
c As Char _
) As UnicodeCategory
public static UnicodeCategory GetUnicodeCategory(
char c
)
Parameters
- c
Type: System.Char
A Unicode character.
Return Value
Type: System.Globalization.UnicodeCategory
A UnicodeCategory value that identifies the group that contains c.
Remarks
The GetUnicodeCategory method does not always return the same UnicodeCategory value as the CharUnicodeInfo.GetUnicodeCategory(Char) method when passed a particular character as a parameter. The CharUnicodeInfo.GetUnicodeCategory(Char) 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(Char).
Examples
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
using System;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
char ch2 = '2';
string str = "Upper Case";
outputBlock.Text += Char.GetUnicodeCategory('a') + "\n";
outputBlock.Text += Char.GetUnicodeCategory(ch2) + "\n";
outputBlock.Text += Char.GetUnicodeCategory(str, 6) + "\n";
}
}
// The example displays the following output:
// LowercaseLetter
// DecimalDigitNumber
// UppercaseLetter
Version Information
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
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Change History
Date |
History |
Reason |
---|---|---|
December 2010 |
Noted that the CharUnicodeInfo.GetUnicodeCategory method is recommended. |
Information enhancement. |