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.
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 nullptr. |
| 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 Char::GetUnicodeCategory method does not always return the same UnicodeCategory value as the CharUnicodeInfo::GetUnicodeCategory(String, Int32) method when it is 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 Char::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 namespace System; int main() { char ch2 = '2'; String^ str = "Upper Case"; Console::WriteLine( Char::GetUnicodeCategory( 'a' ).ToString() ); // Output: S"LowercaseLetter" Console::WriteLine( Char::GetUnicodeCategory( ch2 ).ToString() ); // Output: S"DecimalDigitNumber" Console::WriteLine( Char::GetUnicodeCategory( str, 6 ).ToString() ); // Output: S"UppercaseLetter" }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.