Export (0) Print
Expand All

Char.GetUnicodeCategory Method (String, Int32)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function GetUnicodeCategory( _
   ByVal s As String, _
   ByVal index As Integer _
) As UnicodeCategory
public static UnicodeCategory GetUnicodeCategory(
 string s,
 int index
public: static UnicodeCategory GetUnicodeCategory(
 String* s,
 int index
public static function GetUnicodeCategory(
   s : String,
 index : int
) : UnicodeCategory;


A String.
The character position in s.

Return Value

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


Exception Type Condition
ArgumentNullException s is a null reference (Nothing in Visual Basic).
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.


Character positions in a string are indexed starting from zero.


[Visual Basic, C#, C++] The following sample demonstrates GetUnicodeCategory.

[Visual Basic] 
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

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"

#using <mscorlib.dll>

using namespace System;

int main() {
   char ch2 = '2';
   String* str = S"Upper Case";

   Console::WriteLine(__box(Char::GetUnicodeCategory('a'))->ToString());        // Output: S"LowercaseLetter"
   Console::WriteLine(__box(Char::GetUnicodeCategory(ch2))->ToString());        // Output: S"DecimalDigitNumber"
   Console::WriteLine(__box(Char::GetUnicodeCategory(str, 6))->ToString());        // Output: S"UppercaseLetter"

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Char Structure | Char Members | System Namespace | Char.GetUnicodeCategory Overload List

© 2015 Microsoft