在.Net中,给定一个字符,是否有方法来判断该字符是否属于特定Unicode类别的一部分?我感兴趣的类别这里http://www.fileformat.info/info/unicode/category/index.htm是unicode类中的char?
定义。例如,有一个功能,它这样的事?:
bool isCharInClass(Char c, String class)
,可以这样调用:
SomeClass.isCharInClass("a", "Lo");
在.Net中,给定一个字符,是否有方法来判断该字符是否属于特定Unicode类别的一部分?我感兴趣的类别这里http://www.fileformat.info/info/unicode/category/index.htm是unicode类中的char?
定义。例如,有一个功能,它这样的事?:
bool isCharInClass(Char c, String class)
,可以这样调用:
SomeClass.isCharInClass("a", "Lo");
你可以使用Char.GetUnicodeCategory
或CharUnicodeInfo.GetUnicodeCategory
获取unicode类别(作为UnicodeCategory
)。
使用System.Globalization命名
Console.WriteLine("{0} , {1}", 'a', CharUnicodeInfo.GetUnicodeCategory('a'));
Console.WriteLine("{0} , {1}", 'A', CharUnicodeInfo.GetUnicodeCategory('A'));
Console.WriteLine("{0} , {1}", '1', CharUnicodeInfo.GetUnicodeCategory('1'));
Console.WriteLine("{0} , {1}", '$', CharUnicodeInfo.GetUnicodeCategory('$'));
更多的文档,你可以得到
谢谢你,我不知道我怎么错过了。一个角色是否可能在多个类别中? –
@BradleyUffner否 - 每个字符都在一个类别中。 –