Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if character is a part of Latin alphabet?

Tags:

java

I need to test whether character is a letter or a space before moving on further with processing. So, i

    for (Character c : take.toCharArray()) {
        if (!(Character.isLetter(c) || Character.isSpaceChar(c)))
            continue;

        data.append(c);

Once i examined the data, i saw that it contains characters which look like a unicode representation of characters from outside of Latin alphabet. How can i modify the above code to tighten my conditions to only accept letter characters which fall in range of [a-z][A-Z]?

Is Regex a way to go, or there is a better (faster) way?

like image 542
James Raitsev Avatar asked Feb 06 '12 02:02

James Raitsev


1 Answers

If you specifically want to handle only those 52 characters, then just handle them:

public static boolean isLatinLetter(char c) {
    return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
like image 156
Ernest Friedman-Hill Avatar answered Sep 21 '22 17:09

Ernest Friedman-Hill