printable char in java

前端 未结 2 1589
孤街浪徒
孤街浪徒 2020-11-28 09:12

Does anyone knows how to detect printable characters in java?

After a while ( trial/error ) I get to this method:

    public boolean isPrintableChar(         


        
相关标签:
2条回答
  • 2020-11-28 09:45

    It seems this was the "Font" independent way.

    public boolean isPrintableChar( char c ) {
        Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
        return (!Character.isISOControl(c)) &&
                c != KeyEvent.CHAR_UNDEFINED &&
                block != null &&
                block != Character.UnicodeBlock.SPECIALS;
    }
    
    0 讨论(0)
  • 2020-11-28 09:45

    I'm not perfectly sure whether I understand your problem. But if you want detect if character can be drawn to Graphics object, and if not print some placeholder char you might find usefull:

    Font.canDisplay(int)
    

    It will check whether font can display specific codepoint (it is more that check whether font is displayable at all -- since there are chars that are displayable - like ą - but some fonts cant display them.

    0 讨论(0)
提交回复
热议问题