现成汉字字符串的模糊查找函数

来源:互联网 发布:淘宝清仓甩货图 编辑:程序博客网 时间:2024/04/30 23:46

参见:http://www.vccode.com/file_show.php?id=2457#xx1931xx

而且我给出了 BlurFindStr 函数的改进:
<code>
BOOL BlurFindStr(CString& strSource, CString& strFindCell)
{
int nLenCell = strFindCell.GetLength();
int nLenSource = strSource.GetLength();
if(nLenCell < 1)
return TRUE;
if(nLenSource <1)
return FALSE;
strSource.MakeLower();
strFindCell.MakeLower();

int i = 0; // 正在处理的strSource的下标
while(i < nLenSource)
{
int ii = i; // 保存一个备份
int j=0; // 正在处理的strFindCell的下标
// strSource 的递增量(如果当前是中文,则为2;否则,则为1)
int increment = (strSource.GetAt(ii) & 0x80)? 2 : 1;
while(j < nLenCell)
{
// 都是汉字
if(((strSource.GetAt(ii) & 0x80)) && ((strFindCell.GetAt(j) & 0x80)))
{
if (strSource.GetAt(ii) == strFindCell.GetAt(j) && strSource.GetAt(ii+1) == strFindCell.GetAt(j+1))
{
ii = ii + 2;
j = j + 2;
}
else
{
i = i + increment;
break;
}
}
// strSource是汉字
else if(((strSource.GetAt(ii) & 0x80)) && (!(strFindCell.GetAt(j) & 0x80)))
{
if (IsBlur(strSource.GetAt(ii), strSource.GetAt(ii+1), strFindCell.GetAt(j)))
{
ii = ii + 2;
j = j + 1;
}
else
{
i = i + increment;
break;
}
}
// strFindCell是汉字
else if((!(strSource.GetAt(ii) & 0x80)) && ((strFindCell.GetAt(j) & 0x80)))
{
i = i + increment;
break;
}
// 都不是汉字
else if((!(strSource.GetAt(ii) & 0x80)) && (!(strFindCell.GetAt(j) & 0x80)))
{
if (strSource.GetAt(ii) == strFindCell.GetAt(j))
{
ii++;
j++;
}
else
{
i = i + increment;
break;
}
}
}
if (j >= nLenCell) return TRUE;
}
return FALSE;
}
</code>

 

欢迎讨论,good luck!!