分割字符串:INF "L PRINCE" "shuman" "delaware river" "ft. mifflin" 0.00 0.00 1472.30
我需要的字串为
INF
L PRINCE
shuman
delaware river
ft. mifflin
0.00
0.00
1472.30
求算法,谢谢,100分

解决方案 »

  1.   

    如果就这么一个字符串,你可以用CString类进行操作啊!!!!!!
      

  2.   


    TCHAR szSrc[] = _T("INF \"L PRINCE\" \"shuman\" \"delaware river\" \"ft. mifflin\" 0.00 0.00 1472.30");
    CStringList ListResult;
    TCHAR *p, *pLast;
    BOOL bInQuote = FALSE;for(p = pLast = szSrc; *p != 0; p++){
        if(*p == _T('\"')) {
            bInQuote = !bInQuote;
            continue;
        }
        if(bInQuote) continue;    if(*p == _T(' ')) {
            if(p != pLast) {
                *p = 0;
                ListResult.AddTail(pLast);
                *p = _T(' ');
            }
            pLast = p + 1;
        }
        if(p != pLast) ListResult.AddTail(pLast);
    }
      

  3.   

    写错了一点,重贴。TCHAR szSrc[] = _T("INF \"L PRINCE\" \"shuman\" \"delaware river\" \"ft. mifflin\" 0.00 0.00 1472.30");
    CStringList ListResult;
    TCHAR *p, *pLast;
    BOOL bInQuote = FALSE;for(p = pLast = szSrc; *p != 0; p++){
        if(*p == _T('\"')) {
            bInQuote = !bInQuote;
            continue;
        }
        if(bInQuote) continue;    if(*p == _T(' ')) {
            if(p != pLast) {
                *p = 0;
                ListResult.AddTail(pLast);
                *p = _T(' ');
            }
            pLast = p + 1;
        }
    }
    if(p != pLast) ListResult.AddTail(pLast);
      

  4.   


    void CFenGEStringDlg::OnBtnFenGe() 
    {
    // TODO: Add your control notification handler code here
    CString str1;  //INF
    CString str2;  //L PRINCE
    CString str3;  //shuman
    CString str4;  //delaware river
    CString str5;  //ft. mifflin
    CString str6;  //0.00
    CString str7;  //0.00
    CString str8;  //1472.30
    CString tempString = "INF \"L PRINCE\" \"shuman\" \"delaware river\" \"ft. mifflin\" 0.00 0.00 1472.30"; //取得str1
    int index = tempString.Find(" ",0);
    if(index != -1)
    {
    str1 = tempString.Left(index);
    // MessageBox(str1);
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    }
    //取得str2
    index = -1;
    index = tempString.Find("\"",0);
    if(index != -1)
    {
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    }
    index = -1;
    index = tempString.Find("\"",0);
    if (index != -1)
    {
    str2 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 2));
    // MessageBox(str2);
    }
    //取得str3
    index = -1;
    index = tempString.Find("\"",0);
    if(index != -1)
    {
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    }
    index = -1;
    index = tempString.Find("\"",0);
    if (index != -1)
    {
    str3 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 2));
    // MessageBox(str3);
    }
    //取得str4
    index = -1;
    index = tempString.Find("\"",0);
    if(index != -1)
    {
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    }
    index = -1;
    index = tempString.Find("\"",0);
    if (index != -1)
    {
    str4 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 2));
    // MessageBox(str4);
    }
    //取得str5
    index = -1;
    index = tempString.Find("\"",0);
    if(index != -1)
    {
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    }
    index = -1;
    index = tempString.Find("\"",0);
    if (index != -1)
    {
    str5 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 2));
    // MessageBox(str5);
    }
    //取得str6
    index = -1;
    index = tempString.Find(" ",0);
    if (index != -1)
    {
    str6 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    // MessageBox(str6);
    }
    //取得str7
    index = -1;
    index = tempString.Find(" ",0);
    if (index != -1)
    {
    str7 = tempString.Left(index);
    tempString = tempString.Right(tempString.GetLength() - (index + 1));
    // MessageBox(str7);
    }
    //取得str8
    str8 = tempString;
    // MessageBox(str8);}
      

  5.   


    #include <vector>
    using namespace std;// Parse
    CString strText = _T("INF \"L PRINCE\" \"shuman\" \"delaware river\" \"ft.mifflin\" 0.00 0.00 1472.30");
    LPCTSTR szToken = _T(" \"");
    int curPos = 0;
    CString strTmp(_T(""));
    vector<CString> vec; while(_T("") != (strTmp = strText.Tokenize(szToken, curPos)))
    {
    if(!strTmp.IsEmpty())
    {
    vec.push_back(strTmp);
    }
    } // Output 
    CString strOut(_T(""));
    for(vector<CString>::const_iterator iter = vec.begin(); iter != vec.end(); ++iter)
    {
    strOut += *iter;
    strOut += _T("\r\n");
    }
    AfxMessageBox(strOut);
      

  6.   

    error C2039: 'Tokenize' : is not a member of 'CString'这个不对哦!!!!!!