我有一个名为tablolar的字符串变量,在这种情况下,它的值是“tablo2”,根据我的意图,它不能输入if语句,但它进入,我无法找到原因。
for(int z=0;z<tablolar.size();){
if((tablolar[z]==',')||(tablolar[z]=='a')||(tablolar[z]=='b')
||(tablolar[z]=='c')||(tablolar[z]=='d')||(tablolar[z]=='e')
||(tablolar[z]=='f')||(tablolar[z]=='g')||(tablolar[z]=='h')
||(tablolar[z]=='i')||(tablolar[z]=='j')||(tablolar[z]=='k')
||(tablolar[z]=='l')||(tablolar[z]=='m')||(tablolar[z]=='n')
||(tablolar[z]=='o')||(tablolar[z]=='p')||(tablolar[z]=='q')
||(tablolar[z]=='r')||(tablolar[z]=='s')||(tablolar[z]=='t')
||(tablolar[z]=='u')||(tablolar[z]=='v')||(tablolar[z]=='w')
||(tablolar[z]=='x')||(tablolar[z]=='y')||(tablolar[z]=='z')) {
//enters here but it must not enter
}
答案 0 :(得分:4)
您的检查包括检查当前符号是否为't'
,如果字符串为'tablo2'
,则其第一个字符为't'
。
顺便说一句,这项检查可以更加简单:
if ((tablolar[z] == ',') || (tablolar[z] >= 'a' && tablolar[z] <= 'z'))
// do your work