Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Char.GetUnicodeCategory(String, Int32) trong C# với ví dụ


Phương thức Char.GetUnicodeCategory(String, Int32) trong C# phân loại ký tự tại vị trí được chỉ định trong một chuỗi xác định thành một nhóm được xác định bởi một trong các giá trị UnicodeCategory.

Cú pháp

Dưới đây là cú pháp:

public static System.Globalization.UnicodeCategory GetUnicodeCategory (string str, int index);

Trong đó, str là một chuỗi, trong khi index là vị trí ký tự trong str.

Ví dụ 1

Hãy xem ví dụ sau để triển khai phương thức Char.GetUnicodeCategory(String, Int32):

using System;
using System.Globalization;
public class Demo {
    public static void Main(){
        string val = "amit";
        UnicodeCategory unicode = Char.GetUnicodeCategory(val, 2);
        Console.WriteLine("The value at specific index = " + unicode);
    }
}

Đầu ra

Chương trình sẽ cho ra kết quả sau:

LowercaseLetter

Ví dụ 2

Ví dụ khác với ký tự số:

using System;
using System.Globalization;
public class Demo {
    public static void Main(){
        string val = "hjk9878hj";
        UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);
        Console.WriteLine("The value at specific index = " + unicode);
    }
}

Đầu ra

Chương trình sẽ cho ra kết quả sau:

The value at specific index = DecimalDigitNumber