AllInput 待查找的完整字符串,key 被查找的子字符串
{
CString AllInput = GetAllTxt();
CString key = _T("/r/n")+strGuestName;
CString strLastInput;
CString stemp = AllInput;
int pos = stemp.ReverseFind('/r');
while (pos>0)
{
CString sSub = stemp.Mid(pos); // 获得最后1行字符串
if (sSub.Find(key)>=0)
{
// 最后1行字符串找到匹配字段
strLastInput = AllInput.Mid(pos);
break;
}
else
{
// 在最后1行字符串(pos右边)没有找到匹配字段,把右边部分截掉,用ReverseFind继续向左查找匹配字段
stemp = stemp.Left(pos);
pos = stemp.ReverseFind('/r');
}
}
}
CString 逆向查找字符串
最新推荐文章于 2025-07-14 15:11:51 发布
本文介绍了一种使用C++实现的字符串搜索方法,该方法通过逆向查找特定字符并逐步缩小搜索范围来定位目标子字符串的位置。这种方法适用于需要从大量文本中快速定位含有特定名称行的情况。
2404

被折叠的 条评论
为什么被折叠?



