views:

50

answers:

2

I want to find out if a Chinese character can be displayed, the unidode for it is "\u8D27", how to use the Java Font method canDisplay ? It takes an int, but "8D27" is not an integer, how does it work, do I need another method to translate "8D27" to an int then use canDisplay ? If so how to translate it ?

Edit : To be more precise, how would a method below look like ?

boolean checkFonts(String inputUnicode)
{
  ... what goes here ??? ...
}

So if I call : checkFonts("\u8D27") , I can get a yes no answer.

Frank

+4  A: 

8D27 is in hex, so you can write 0x8D27 as a literal.

e.g.

private int codePoint = 0x8D27;

The \uXXXX syntax represents the character itself at that code point and is used such that you can express Unicode characters in ASCII.

Brian Agnew
+1  A: 

The canDisplay() method also accepts a char, so why not just get the first character of the string:

return font.canDisplay(inputUnicode.charAt(0));

And FWIW, you can convert between char and int just by casting:

int codePoint = 0x8D27;
char myCharacter = (char) codePoint;
cygri
Great, how to convert "\u8D27" to int in my Java program ?
Frank
String character = "\u8D27"; int codepoint = (int) character.charAt(0);
cygri