Char.GetUnicodeCategory Method

Definition

将 Unicode 字符分类到由一个 UnicodeCategory 值标识的组中。Categorizes a Unicode character into a group identified by one of the UnicodeCategory values.

Overloads

GetUnicodeCategory(Char)

将指定的 Unicode 字符分类到由一个 UnicodeCategory 值标识的组中。Categorizes a specified Unicode character into a group identified by one of the UnicodeCategory values.

GetUnicodeCategory(String, Int32)

将指定字符串中位于指定位置的字符分类到由一个 UnicodeCategory 值标识的组中。Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.

GetUnicodeCategory(Char)

将指定的 Unicode 字符分类到由一个 UnicodeCategory 值标识的组中。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

要分类的 Unicode 字符。The Unicode character to categorize.

Returns

UnicodeCategory

一个 UnicodeCategory 值,它标识包含 c 的组。A UnicodeCategory value that identifies the group that contains c.

Examples

下面的代码示例演示 GetUnicodeCategoryThe 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"
    }
}
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

将特定字符作为参数传递时,Char.GetUnicodeCategory 方法不会始终返回与 CharUnicodeInfo.GetUnicodeCategory(Char) 方法相同的 UnicodeCategory 值。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. CharUnicodeInfo.GetUnicodeCategory(Char) 方法旨在反映 Unicode 标准的当前版本。The CharUnicodeInfo.GetUnicodeCategory(Char) method is designed to reflect the current version of the Unicode standard. 相反,尽管 Char.GetUnicodeCategory 方法通常反映 Unicode 标准的当前版本,但它可能会根据标准版的以前版本返回字符类别,或返回与当前标准不同的类别,以便保留向后兼容性。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. 因此,建议使用 CharUnicodeInfo.GetUnicodeCategory(Char) 方法,而不是 Char.GetUnicodeCategory(Char)As a result, we recommend that you use the CharUnicodeInfo.GetUnicodeCategory(Char) method instead of Char.GetUnicodeCategory(Char).

.NET Framework 4.6.2.NET Framework 4.6.2开始,将根据Unicode 标准版本 8.0.0对 unicode 字符进行分类。Starting with the .NET Framework 4.6.2.NET Framework 4.6.2, Unicode characters are classified based on The Unicode Standard, Version 8.0.0. 在从 .NET Framework 4.NET Framework 4.NET Framework 4.6.1.NET Framework 4.6.1的 .NET Framework 版本中,将根据Unicode 标准版本 6.3.0进行分类。In versions of the .NET Framework from the .NET Framework 4.NET Framework 4 to the .NET Framework 4.6.1.NET Framework 4.6.1, they are classified based on The Unicode Standard, Version 6.3.0.

See also

GetUnicodeCategory(String, Int32)

将指定字符串中位于指定位置的字符分类到由一个 UnicodeCategory 值标识的组中。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

s
String

一个 StringA String.

index
Int32

s 中的字符位置。The character position in s.

Returns

UnicodeCategory

一个 UnicodeCategory 枚举常数,标识包含 index 中位于 s 处的字符的组。A UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.

Exceptions

snulls is null.

index 小于零或大于 s 中最后一个位置。index is less than zero or greater than the last position in s.

Examples

下面的示例演示 GetUnicodeCategoryThe 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"
    }
}
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.

将特定字符作为参数传递时,Char.GetUnicodeCategory 方法不会始终返回与 CharUnicodeInfo.GetUnicodeCategory(String, Int32) 方法相同的 UnicodeCategory 值。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. CharUnicodeInfo.GetUnicodeCategory(String, Int32) 方法旨在反映 Unicode 标准的当前版本。The CharUnicodeInfo.GetUnicodeCategory(String, Int32) method is designed to reflect the current version of the Unicode standard. 相反,尽管 Char.GetUnicodeCategory 方法通常反映 Unicode 标准的当前版本,但它可能会根据标准版的以前版本返回字符类别,或返回与当前标准不同的类别,以便保留向后兼容性。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. 因此,建议使用 CharUnicodeInfo.GetUnicodeCategory(Char) 方法,而不是 Char.GetUnicodeCategory(String, Int32)As a result, we recommend that you use the CharUnicodeInfo.GetUnicodeCategory(Char) method instead of Char.GetUnicodeCategory(String, Int32).

.NET Framework 4.6.2.NET Framework 4.6.2开始,将根据Unicode 标准版本 8.0.0对 unicode 字符进行分类。Starting with the .NET Framework 4.6.2.NET Framework 4.6.2, Unicode characters are classified based on The Unicode Standard, Version 8.0.0. 在从 .NET Framework 4.NET Framework 4.NET Framework 4.6.1.NET Framework 4.6.1的 .NET Framework 版本中,将根据Unicode 标准版本 6.3.0进行分类。In versions of the .NET Framework from the .NET Framework 4.NET Framework 4 to the .NET Framework 4.6.1.NET Framework 4.6.1, they are classified based on The Unicode Standard, Version 6.3.0.

See also

Applies to