Char.GetUnicodeCategory Method (Char)

Categorizes a specified Unicode character into a group identified by one of the UnicodeCategory values.

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

public static UnicodeCategory GetUnicodeCategory(
	char c
)

Parameters

c
Type: System.Char
The Unicode character to categorize.

Return Value

Type: System.Globalization.UnicodeCategory
A UnicodeCategory value that identifies the group that contains c.

The Char.GetUnicodeCategory method does not always return the same UnicodeCategory value as the CharUnicodeInfo.GetUnicodeCategory(Char) method when it is 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 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(Char).

The following code example demonstrates GetUnicodeCategory.


using System;

public class GetUnicodeCategorySample {
	public static void Main() {
		char ch2 = '2';
		string str = "Upper Case";

		Console.WriteLine(Char.GetUnicodeCategory('a'));		// Output: "LowercaseLetter"
		Console.WriteLine(Char.GetUnicodeCategory(ch2));		// Output: "DecimalDigitNumber"
		Console.WriteLine(Char.GetUnicodeCategory(str, 6));		// Output: "UppercaseLetter"
	}
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft