我知道肯定有更简单的检查方法,但这就是我现在正在做的事情。
if (g.charAt(0) == 'a' || g.charAt(0) =='b' || g.charAt(0) =='c' ||
g.charAt(0) == 'd' || g.charAt(0) =='e' || g.charAt(0) =='f' ||
g.charAt(0) == 'g' || g.charAt(0) =='h')
最佳答案
依赖于字符排序和 a..h is a consecutive range :
char firstChar = g.charAt(0);
if (firstChar >= 'a' && firstChar <= 'h') {
// ..
}
关于java - 如何检查某个位置的字符串是否包含字符 a-h?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21587658/