简体   繁体   English

在.NET中,与Java的Character.isDefined最接近的是什么?

[英]What is the nearest equivalent to Java's Character.isDefined, in .NET?

Java has a Character.isDefined method, but there's no equivalent on the char class in .NET. Java有一个Character.isDefined方法,但是.NET中的char类没有等价物。

I'm aware that Microsoft's old Java libraries have this , but I don't want to depend on that library if I can avoid it. 我知道微软的旧Java库有这个 ,但我不想依赖那个库,如果我可以避免它。

Is there a built in equivalent in .NET somewhere? .NET中是否有内置的等价物? Or does calling all the available .is* methods combinatorially produce the same result? 或者调用所有可用的.is *方法组合产生相同的结果? (eg char.IsLetter(x) || char.IsSymbol(x) etc....) (例如char.IsLetter(x)|| char.IsSymbol(x)等....)

You could try with 你可以试试

int utf32 = 0x1FFFF;
string surrogate = Char.ConvertFromUtf32(utf32);
var isDefined = char.GetUnicodeCategory(surrogate, 0) != UnicodeCategory.OtherNotAssigned;

You can use char.GetUnicodeCategory(char) directly if you have a character from the base BMP. 如果您有基本BMP中的字符,则可以直接使用char.GetUnicodeCategory(char)

Note that each version of .NET supports different releases of Unicode, so what it will return is dependant of the version of Unicode used by the current version of .NET/current OS. 请注意,每个版本的.NET都支持不同版本的Unicode,因此返回的内容取决于当前版本的.NET /当前操作系统使用的Unicode版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM