C# 中的 Char.GetUnicodeCategory(String, Int32) 方法示例
csharpserver side programmingprogramming更新于 2025/9/18 16:45:00
C# 中的 Char.GetUnicodeCategory(String, Int32) 方法将指定字符串中指定位置的字符归类到由 UnicodeCategory 值之一标识的组中。
语法
以下是语法 −
public static System.Globalization.UnicodeCategory GetUnicodeCategory (string str, int index);
上面,str 是一个字符串,而 index 是 str 中的字符位置。
示例
现在让我们看一个实现 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);
}
}
输出
这将产生以下输出 −
LowercaseLetter
示例
现在让我们看另一个例子 −
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);
}
}
输出
这将产生以下输出 −
The value at specific index = DecimalDigitNumber

