Char.GetUnicodeCategory Char.GetUnicodeCategory Char.GetUnicodeCategory Char.GetUnicodeCategory Method

Definition

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

Overloads

GetUnicodeCategory(Char) GetUnicodeCategory(Char) GetUnicodeCategory(Char) GetUnicodeCategory(Char)

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

GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32)

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

GetUnicodeCategory(Char) GetUnicodeCategory(Char) GetUnicodeCategory(Char) GetUnicodeCategory(Char)

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

public:
 static System::Globalization::UnicodeCategory GetUnicodeCategory(char c);
public static System.Globalization.UnicodeCategory GetUnicodeCategory (char c);
static member GetUnicodeCategory : char -> System.Globalization.UnicodeCategory
Public Shared Function GetUnicodeCategory (c As Char) As UnicodeCategory

Parameters

c
Char Char Char Char

The Unicode character to categorize.

Returns

A UnicodeCategory value that identifies the group that contains c.

Examples

The following code 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"
}

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"
	}
}
Imports System

Module GetUnicodeCategorySample

    Sub Main()

        Dim ch2 As Char
        ch2 = "2"c
        Dim str As String
        str = "Upper Case"

        Console.WriteLine(Char.GetUnicodeCategory("a"c))    ' Output: "1" (LowercaseLetter)
        Console.WriteLine(Char.GetUnicodeCategory(ch2))     ' Output: "8" (DecimalDigitNumber)
        Console.WriteLine(Char.GetUnicodeCategory(str, 6))  ' Output: "0" (UppercaseLetter)

    End Sub

End Module

Remarks

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).

Starting with the .NET Framework 4.6.2, Unicode characters are classified based on The Unix Standard, Version 8.0.0. In versions of the .NET Framework from the .NET Framework 4 to the .NET Framework 4.6.1, they are classified based on The Unix Standard, Version 6.3.0.

See also

GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32) GetUnicodeCategory(String, Int32)

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

public:
 static System::Globalization::UnicodeCategory GetUnicodeCategory(System::String ^ s, int index);
public static System.Globalization.UnicodeCategory GetUnicodeCategory (string s, int index);
static member GetUnicodeCategory : string * int -> System.Globalization.UnicodeCategory
Public Shared Function GetUnicodeCategory (s As String, index As Integer) As UnicodeCategory

Parameters

index
Int32 Int32 Int32 Int32

The character position in s.

Returns

A UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.

Exceptions

Examples

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"
}

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"
	}
}
Imports System

Module GetUnicodeCategorySample

    Sub Main()

        Dim ch2 As Char
        ch2 = "2"c
        Dim str As String
        str = "Upper Case"

        Console.WriteLine(Char.GetUnicodeCategory("a"c))    ' Output: "1" (LowercaseLetter)
        Console.WriteLine(Char.GetUnicodeCategory(ch2))     ' Output: "8" (DecimalDigitNumber)
        Console.WriteLine(Char.GetUnicodeCategory(str, 6))  ' Output: "0" (UppercaseLetter)

    End Sub

End Module

Remarks

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).

Starting with the .NET Framework 4.6.2, Unicode characters are classified based on The Unix Standard, Version 8.0.0. In versions of the .NET Framework from the .NET Framework 4 to the .NET Framework 4.6.1, they are classified based on The Unix Standard, Version 6.3.0.

See also

Applies to