Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Char.GetUnicodeCategory Method (String, Int32)

Updated: December 2010

Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static UnicodeCategory GetUnicodeCategory(
	string s,
	int index
)

Parameters

s
Type: System.String

A String.

index
Type: System.Int32

The character position in s.

Return Value

Type: System.Globalization.UnicodeCategory
A UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.
ExceptionCondition
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 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 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"
	}
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Date

History

Reason

December 2010

Noted that the CharUnicodeInfo.GetUnicodeCategory method is recommended.

Information enhancement.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.