比較字符串不區分大小寫

int compareAb(const char* dst,const char* src){


unsigned char s_tolowerTable[256];
for(int i = 0; i < 256; ++i)    //初始化不分大小寫的數組
    s_tolowerTable[i] = (unsigned char)tolower(i);

//不區分大小寫進行比較 知道完全匹配結束 或 中途不匹配結束
for( ; *dst && *src && s_tolowerTable[(unsigned char)(*dst)] == s_tolowerTable[(unsigned char)(*src)]; ++dst, ++src)
        ;
//返回0 爲匹配相等  返回其它值 匹配不相等
return s_tolowerTable[(unsigned char)(*dst)] - s_tolowerTable[(unsigned char)(*src)];
}

發佈了27 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章