Char.GetUnicodeCategory Method (String, Int32)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.
Assembly: mscorlib (in mscorlib.dll)
Return Value
Type: System.Globalization.UnicodeCategoryA UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is null. |
| 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.
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