以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  在字符串中查找完全匹配的单词  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=56383)


--  作者:卷积内核
--  发布时间:12/5/2007 9:54:00 AM

--  在字符串中查找完全匹配的单词
比如,字符串为,This is a (word123) .如果我查找word,判定为该字符串不存在,查找word123,则认为存在,找到后返回指向w字符位置位置的指针。(单词word123前后的字符如果是非数字和非字母则认为该字符串存在)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
没有这样的函数,不过实现起来很简单,只要用CString::Find()找到要找的字符串,就可以得它前后的字符,只要前后的字符都不是数字或字母就OK啦
int NewFind(CString strAll,CString strFind)
{
int nPos= strAll.Find(strFind);
char per = strAll[nPos-1];
char rear = strAll[nPos+strFind.GetLength()];
if((per>='0' && per <=9)||(per>='a' && per<='z')||(per>='A' && per<='Z'))
return -1;
if((rear>='0' && rear <=9)||(rear>='a' && rear<='z')||(rear>='A' && rear<='Z'))
return -1;
return nPos;
}

}//该函数的返回值是-1表示未找到匹配,如>=0则表示找到匹配的位置。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms