如何实现CString::Find循环(有理必有分加) 现在我已经用CString::Find对一个文件查找制定内容获得成功,但因为文件里有很多需要的内容,且很相似,我想实现循环获取,请问各位谁能告诉我如何才能实现循环获取。事情紧急,请抓紧时间抢分,明天中午准时结贴! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString Find是对字符串查找 不是文件查找 按我的理解楼主是将其文件行内容放到一个CString对象中如果是在CString 中去查找指定的内容的话也就是搜索子字符串,你也可以搜索到一个字符串后将搜索的位置重新定位改变来查找,直到搜索完毕。int Find(LPCTSTR lpszSub,int nStart) const 函数 int index = 1;while(index != -1){ index = str.Find(...); ....做些操作 str = str.Right(...);} 给个详细代码,骗点分吧:CString strContent = _T(""); //你从文件中读入的内容CString strKeyword = _T(""); //你需要查找的关键字... ... //为strContent和strKeyword赋值int nStart = 0;int nIndex = 0;do{ nIndex = strContent.Find(strKeyword, nStart); if(nIndex>=0) { //查找到一条记录 CString strFindItem = strContent.Left(nIndex+1); //截取你想要的那段 //继续你的后续处理 ... ... nStart = nIndex + 1; } else { break; //查找完成 }while(1); 给个详细代码,骗点分吧: CString strContent = _T(""); //你从文件中读入的内容 CString strKeyword = _T(""); //你需要查找的关键字 ... ... //为strContent和strKeyword赋值 int nStart = 0; int nIndex = 0; do { nIndex = strContent.Find(strKeyword, nStart); if(nIndex>=0) { //查找到一条记录 CString strFindItem = strContent.Left(nIndex+1); //截取你想要的那段 //继续你的后续处理 ... ... nStart = nIndex + 1; } else { break; //查找完成 } }while(1); 可以考虑将查找的字符作为参数,写一个函数。如昨天的查找'(',')',你就可以写一个函数如LPCTSTR DevideString(TCHAR ch1,TCHAR ch2); UINT nBytesRead = cFile.Read( pbuf, cFile.GetLength()); CString str; str=pbuf; str=str.Right((str.GetLength()-str.Find("OJDL("))-5); str=str.Left(str.Find(")")); CString sPath="1.txt"; CStdioFile myFileWrite(sPath,CFile::modeWrite|CFile::modeCreate); myFileWrite.WriteString(str);呵呵! 子对话框 改变大小 老问题 删除注册表 ERROR_ACCESS_DENIED 请问可以让spy++检测不到程序中的主窗口和子窗口吗? listen 的socket close前有没有必要shutdown()? 如何在mfc中播放大型的wav文件(求代码) 我没分了,帮帮我吧! 郁闷,散分!!! VC的优势何在 关于winNT的拨号服务问题! 字符转换的问题 vc 里的HANDLE类型在activeX控件里对应什么类型? MFC界面数据交换问题
按我的理解楼主是将其文件行内容放到一个CString对象中
如果是在CString 中去查找指定的内容的话也就是搜索子字符串,
你也可以搜索到一个字符串后将搜索的位置重新定位改变来查找,直到搜索完毕。
int Find(LPCTSTR lpszSub,int nStart) const 函数
while(index != -1)
{
index = str.Find(...);
....做些操作
str = str.Right(...);
}
CString strKeyword = _T(""); //你需要查找的关键字... ... //为strContent和strKeyword赋值int nStart = 0;
int nIndex = 0;
do
{
nIndex = strContent.Find(strKeyword, nStart);
if(nIndex>=0)
{
//查找到一条记录
CString strFindItem = strContent.Left(nIndex+1); //截取你想要的那段
//继续你的后续处理
... ...
nStart = nIndex + 1;
}
else
{
break; //查找完成
}
while(1);
CString strContent = _T(""); //你从文件中读入的内容
CString strKeyword = _T(""); //你需要查找的关键字 ... ... //为strContent和strKeyword赋值 int nStart = 0;
int nIndex = 0;
do
{
nIndex = strContent.Find(strKeyword, nStart);
if(nIndex>=0)
{
//查找到一条记录
CString strFindItem = strContent.Left(nIndex+1); //截取你想要的那段
//继续你的后续处理
... ...
nStart = nIndex + 1;
}
else
{
break; //查找完成
}
}while(1);
CString str;
str=pbuf;
str=str.Right((str.GetLength()-str.Find("OJDL("))-5);
str=str.Left(str.Find(")")); CString sPath="1.txt";
CStdioFile myFileWrite(sPath,CFile::modeWrite|CFile::modeCreate);
myFileWrite.WriteString(str);
呵呵!