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
[C#]
public static UnicodeCategory GetUnicodeCategory(
 string s,
 int index
);
[C++]
public: static UnicodeCategory GetUnicodeCategory(
 String* s,
 int index
);
[JScript]
public static function GetUnicodeCategory(
   s : String,
 index : int
) : UnicodeCategory;

Parameters

s
A String.
index
The character position in s.

Return Value

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

Exceptions

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.

Remarks

Character positions in a string are indexed starting from zero.

Example

[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

[C#] 
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"
    }
}

[C++] 
#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.

Requirements

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

Show:
© 2015 Microsoft