-2

我有一个名为 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
}
4

1 回答 1

4

您的检查包括检查当前符号是否为't',如果字符串为'tablo2',则其第一个字符为't'

顺便说一句,这个检查可以更简单地完成:

if ((tablolar[z] == ',') || (tablolar[z] >= 'a' && tablolar[z] <= 'z'))
    // do your work
于 2013-04-25T09:02:45.953 回答