CString strtmp;
strtmp.Format(_T("123sd#<FileName>xxx234@!asd%%wr3</FileName>"));
int nLength = strtmp.GetLength(); CString strFindBeg;
CString strFindEnd;
strFindBeg.Format(_T("<FileName>"));
strFindEnd.Format(_T("</FileName>")); int nBeg = 0;
int nEnd = 0; nBeg = strtmp.Find(strFindBeg);
nEnd = strtmp.Find(strFindEnd); TCHAR testChar = _T('\0');
testChar = strtmp.GetAt(nEnd); // '<' CString strTarget;
strTarget = strtmp.Mid(nBeg + strFindBeg.GetLength(), nEnd/* - strFindEnd.GetLength()*/);
AfxMessageBox(strTarget);
Questions::
1. 为什么最后的strTarget显示的字符串要多显示5个字符"</File"2. 要求是只显示<FileName>和</FileName>中间的字符串.求解

解决方案 »

  1.   


    CString strtmp;
    strtmp.Format(_T("123sd#<FileName>xxx234@!asd%%wr3</FileName>asdfasaerqwer23412df"));
    int nLength = strtmp.GetLength(); CString strFindBeg;
    CString strFindEnd;
    strFindBeg.Format(_T("<FileName>"));
    strFindEnd.Format(_T("</FileName>"));
    int nBeg = 0;
    int nEnd = 0; nBeg = strtmp.Find(strFindBeg);
    nEnd = strtmp.Find(strFindEnd); TCHAR testChar = _T('\0');
    testChar = strtmp.GetAt(nEnd); CString strTarget;
    strTarget = strtmp.Mid(nBeg + strFindBeg.GetLength(), nEnd/* - strFindEnd.GetLength()*/);
    AfxMessageBox(strTarget);这样strTarget的值是xxx234@!asd%wr3</FileName>asdfa
      

  2.   

    CString Mid( int nFirst, int nCount ) const;谢谢, 没注意看函数声明....