现在我已经用CString::Find对一个文件查找制定内容获得成功,但因为文件里有很多需要的内容,且很相似,我想实现循环获取,请问各位谁能告诉我如何才能实现循环获取。事情紧急,请抓紧时间抢分,明天中午准时结贴!

解决方案 »

  1.   

    CString  Find是对字符串查找 不是文件查找  
    按我的理解楼主是将其文件行内容放到一个CString对象中
    如果是在CString 中去查找指定的内容的话也就是搜索子字符串,
    你也可以搜索到一个字符串后将搜索的位置重新定位改变来查找,直到搜索完毕。
    int Find(LPCTSTR lpszSub,int nStart) const 函数
      
      

  2.   

    int index = 1;
    while(index != -1)
    {
      index = str.Find(...);
      ....做些操作
      str = str.Right(...);
    }
      

  3.   

    给个详细代码,骗点分吧: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);
      

  4.   

    给个详细代码,骗点分吧: 
    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);
      

  5.   

    可以考虑将查找的字符作为参数,写一个函数。如昨天的查找'(',')',你就可以写一个函数如LPCTSTR DevideString(TCHAR ch1,TCHAR ch2);
      

  6.   

    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);
    呵呵!