Shadi
Shadi

Reputation: 93

How Can I detect Unknown/Unassigned Unicode characters in my java program?

I want to write a java program to print Unicode characters. I want to detect and not print Unknown/Unassigned CHaracters (which are shown by a rectangular). I have tried "isDefined" and "isISOControl" from "Character" class, but it does not work. Does anybody know the solution? it will be a big help for me.

Thanks.

Upvotes: 0

Views: 1252

Answers (1)

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143144

The characters that are shown as a rectangle (on Windows) are ones that aren't available in the font you're using. While you could filter out a lot of them by filtering out undefined and control characters, it's entirely possible that the problem you're running into is that your font doesn't support certain ranges of valid characters (which is typical -- very few fonts define glyphs for all defined Unicode characters).

If your goal is really to remove characters that render as a rectangle, you can use the canDisplay method in Font.

Upvotes: 3

Related Questions