views:

955

answers:

1

I have to perform a check on a character variable to see whether or not it is a currency symbol. I have discovered the Character.UnicodeBlock.CURRENCY_SYMBOLS constant however I am unsure of how to use this to determine whether or not the character is in that block.

If anyone has done this before help would be much appreciated.

Thanks

+12  A: 

Yep, according to Java API - that's the constant you are looking for.

To get the char type, use the Character.getType(c) static method, like so:

char c = '$';
System.out.println(Character.getType(c) == Character.CURRENCY_SYMBOL);
// prints true
Yuval A
good answer.I just solved this problem slightly differently :-<code>if (Character.UnicodeBlock.of(c.charValue()) == Character.UnicodeBlock.CURRENCY_SYMBOLS) { return true; }</code>Thanks for your answer.
Scottm
...damn - thought you could put code tag in comments :(
Scottm
doesn't work in comments :)
Yuval A