简体   繁体   中英

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.

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.

Is there a built in equivalent in .NET somewhere? Or does calling all the available .is* methods combinatorially produce the same result? (eg char.IsLetter(x) || char.IsSymbol(x) etc....)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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