System.Globalization.CharUnicodeInfo.GetUnicodeCategory Method

Gets the Unicode category of the character at the specified index of the specified string.

Syntax

public static UnicodeCategory GetUnicodeCategory (string s, int index)

Parameters

s
The string containing the Unicode character for which to get the Unicode category.
index
The index of the Unicode character for which to get the Unicode category.

Returns

A System.Globalization.UnicodeCategory value indicating the category of the character at the specified index of the specified string.

Remarks

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 System.Globalization.UnicodeCategory class returns the category of a Unicode character. For more information on Unicode characters, see the tp://go.microsoft.com/fwlink/?linkid=37123.

If the char object at position index is the first character of a valid surrogate pair, the CharUnicodeInfo.GetUnicodeCategory(string, int) method returns the Unicode category of the surrogate pair instead of returning UnicodeCategory.Surrogate. For example, the Ugaritic alphabet occupies code points U+10380 to U+1039F. The following example uses the char.ConvertFromUtf32(int) 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 CharUnicodeInfo.GetUnicodeCategory(string, int) method returns UnicodeCategory.OtherLetter if it is passed the high surrogate of this character, which indicates that it considers the surrogate pair. However, if it is passed the low surrogate, it considers only the low surrogate in isolation and returns UnicodeCategory.Surrogate.

code reference: System.Globalization.CharUnicodeInfo.GetUnicodeCategory#2

Note that CharUnicodeInfo.GetUnicodeCategory(string, int) method does not always return the same System.Globalization.UnicodeCategory value as the char.GetUnicodeCategory(string, int) method when passed a particular character as a parameter. The CharUnicodeInfo.GetUnicodeCategory(string, int) method is designed to reflect the current version of the Unicode standard. In contrast, although the char.GetUnicodeCategory(string, int) 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.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0