在Java中检查字符串中的字母 [英] Checking for Alphabets in a String in java
本文介绍了在Java中检查字符串中的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串"BC + D * E-".我想检查字符串的每个字符是否是字母.我尝试使用isLetter(),但它甚至会将=,*和-都视为字母.请您帮我一下.谢谢!
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 - as alphabets.Can you please help me in this.Thanks in advance
推荐答案
尝试
String s = "BC+D*E-=";
for (int i = 0; i < s.length(); i++) {
char charAt2 = s.charAt(i);
if (Character.isLetter(charAt2)) {
System.out.println(charAt2 + "is a alphabet");
}
}
这篇关于在Java中检查字符串中的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文