char* stristr(char* pString, char* pFind)
{
unsigned long pFind_len=0;
unsigned long cmp_len=0;
char *pt1 = NULL, *pt2 = NULL;
char* pString_pt = pString;
///////////////
pFind_len = strlen(pFind);
if (pFind_len == 0) {
return(NULL);
}
while (*pString_pt != 0) {
// 匹配
pt1 = pString_pt;
pt2 = pFind;
cmp_len = 0;
while ((cmp_len < pFind_len) && (*pt1 != 0)) {
// 转成小写进行比较
if ((*pt1 >= 'A') && (*pt1 <= 'Z') && (*pt2 >= 'a') && (*pt2 <= 'z')) {
if((*pt1+32) != (*pt2)){ break; }
} else if((*pt1 >= 'a') && (*pt1 <= 'z') && (*pt2 >= 'A') && (*pt2 <= 'Z')) {
if((*pt1 - 32) != (*pt2)) {
break;
}
} else {
if (*pt1 != *pt2) {
break;
}
}
cmp_len++;
pt1++;
pt2++;
}// while(pt1,pt2)
// 匹配结果
if (cmp_len == pFind_len) {
return(pString_pt);
}
if (*pt1 == 0) {
return(NULL);
}// 匹配长度不够了
// 继续
pString_pt++;
}// while(pString)
return NULL;
}
标签:--,pFind,len,C语言,char,大小写,&&,pString,pt1
From: https://www.cnblogs.com/stlong/p/17633573.html