Checking for Alphabets in a String in java

后端 未结 6 1497
灰色年华
灰色年华 2021-01-16 21:46

I have a string \"BC+D*E-\". I want to check each character of the string whether it is an alphabet or not. I tried using isLetter() but it does consider even the = , * and

6条回答
  •  情深已故
    2021-01-16 22:15

    You can use ASCII value of English letters. e.g.

    for (char c : "BC+D*E-".toCharArray())
    {
      int value = (int) c;
      if ((value >= 65 && value <= 90) || (value >= 97 && value <= 122))
      {
        System.out.println("letter");
      }
    }
    

    You can find ASCII table here: http://www.asciitable.com/

提交回复
热议问题