How can I determine if String contains only alphabets and I want to have little more than [a-zA-Z]+, so is there any way to determine alphabets by Locale?
+5
A:
The Character
class has methods such as isLetter
which will be able to determine if a character is a letter as defined in the API specification for the method.
There is also another approach of using the Character.UnicodeBlock
class which is able to return whether a character is in a specific character block of Unicode.
For example, I had to determine whether a character was a full-width katakana character, and to be able to do so, I had to use the Character.UnicodeBlock.of
method:
boolean isKatakana =
Character.UnicodeBlock.of(c) == Character.UnicodeBlock.KATAKANA;
Also to add, the character at a certain index of a String
can be retrieved by using the charAt(int)
method, and the Unicode code point can be retrieved by the codePointAt(int)
method.
coobird
2009-05-01 11:03:32