Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

c#

.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? (e.g. char.IsLetter(x) || char.IsSymbol(x) etc....)

like image 394
pattermeister Avatar asked Sep 06 '13 08:09

pattermeister


1 Answers

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.

like image 76
xanatos Avatar answered Oct 04 '22 21:10

xanatos