Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To check whether a character is of English Alphabet (a-zA-Z)

The method Character.isLetter(Char c) tells whether the character is a unicode letter. What if I want to check for English letters (a-zA-Z) without regex.

like image 291
dharakk Avatar asked Jan 20 '15 18:01

dharakk


People also ask

How do you know if a character is English letter?

By using str. isalpha() you can check if it is a letter.

How do you check if a character is a number or letter?

We can check whether the given character in a string is a number/letter by using isDigit() method of Character class. The isDigit() method is a static method and determines if the specified character is a digit.

How do I check if a string has a alphabet?

Regex can be used to check a string for alphabets. String. matches() method is used to check whether or not the string matches the given regex.


1 Answers

Easy

char c = ...;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
  //english letter
}
like image 163
ControlAltDel Avatar answered Oct 12 '22 06:10

ControlAltDel