CString a ="阿俊,同学,我是李雪,我昵称是125,";获取变量a逗号之间的数据保持到一个数组里面

解决方案 »

  1.   

    This global function can be used to extract a substring from a given source string.  
    BOOL AFXAPI AfxExtractSubString (
       CString& rString,
       LPCTSTR lpszFullString,
       int iSubString,
       TCHAR chSep = '\n'
    );
     Parameters
    rString
    Reference to a CString object that will receive an individual substring. lpszFullString
    String containing the full text of the string to extract from. iSubString
    Zero-based index of the substring to extract from lpszFullString. chSep
    Separator character used to delimit substrings. Return Value
    TRUE if the function successfully extracted the substring at the provided index; otherwise, FALSE. 
      

  2.   


    // The following example extracts a series of name, value pairs from a
    // given source string:// Input string consisting of a number of name, value pairs
    LPCTSTR lpszSource = _T("\"Name\"=\"John Smith\"\n")
       _T("\"Company\"=\"Contoso, Ltd\"\n\"Salary\"=\"25,000\"");CString strNameValue; // an individual name, value pairint i = 0; // substring index to extract
    while (AfxExtractSubString(strNameValue, lpszSource, i))
    {
       // Prepare to move to the next substring
       i++;   CString strName, strValue; // individual name and value elements   // Attempt to extract the name element from the pair
       if (!AfxExtractSubString(strName, strNameValue, 0, _T('=')))
       {
          // Pass an error message to the debugger for display
          OutputDebugString(_T("Error extracting name\r\n"));
          continue;
       }   // Attempt to extract the value element from the pair
       if (!AfxExtractSubString(strValue, strNameValue, 1, _T('=')))
       {
          // Pass an error message to the debugger for display
          OutputDebugString(_T("Error extracting value element\r\n"));
          continue;
       }   // Pass the name, value pair to the debugger for display
       CString strOutput = strName + _T(" equals ") + strValue + _T("\r\n");
       OutputDebugString(strOutput);
    }
      

  3.   

    #include <afx.h>
    #include <afxwin.h>
    #include <iostream>
    using namespace std;
    int main(int argc, char* argv[])
    {
    CString strTemp = TEXT("阿俊,同学,我是李雪,我昵称是125,");
    CStringArray strArray;
    CString strName(_T(""));
    int nTokenize = 0;
    strName = strTemp.Tokenize(_T(","), nTokenize);
    while (!strName.IsEmpty())
    {
    strArray.Add(strName);
    strName = strTemp.Tokenize(_T(","), nTokenize);
    }
    cout<<strArray.GetCount()<<endl;
    return 0;
    }
      

  4.   

    CString szInfo="阿俊,同学,k,我昵称是125,1,"; int iloc1 = 0;
    int iloc2 = 0;
    int iLength = szInfo.Replace(",",",");
    iloc2=szInfo.Find(",", iloc1+1) != -1 ? szInfo.Find(",", iloc1) : szInfo.Find(";", iloc1);
    for(int i = 0; i < iLength; i++)
    {
    MessageBox(szInfo.Mid(iloc1, iloc2 - iloc1));
    iloc1 = iloc2+1;
    iloc2 = szInfo.Find(",", iloc1+1) != -1 ? szInfo.Find(",", iloc1) : szInfo.Find(";", iloc1);
    }
      

  5.   

    error C2039: 'Tokenize' : is not a member of 'CString'
    我VC6.0
      

  6.   


    wchar_t first[]=_T("-1234567890");
    wchar_t last[]=_T(" ,\n\t\v\f\r\"\0");
    CString a = _T("阿俊,同学,我是李雪,我昵称是125,");
    a=a.Right(a.GetLength()-a.FindOneOf(first));
    a = a.Left(a.FindOneOf(last));
    int n = _wtoi(a);
      

  7.   

    CString *SplitStrings(CString str,CString array[])
    {

    CString strtemp=str;
    int nStringNum=0;
    int ipos;
    while(strtemp.GetLength())
    {
    ipos = strtemp.Find(',');
    if(ipos!=-1)
    {
    array[nStringNum]=strtemp.Left(ipos);
                strtemp=strtemp.Mid(ipos+1);
    nStringNum++;
    }
    else
    {
    array[nStringNum]=strtemp;
    break;
    }
    }
    return array;
    } CString str = "Hello,My name is Zouyu,you can call me talent";
        CString strarray[MAX_PATH];
        SplitStrings(str,strarray);
    记得给分啊,谢谢