有一个函数   strURL
我需要找它的每一个&并把前面的内容复制给新的函数比如
www.xx.com/asp?id=2&y=2009&m=03&d=12
我需要url1=  www.xx.com/asp?id=2
url2= www.xx.com/asp?id=2&y=2009
url3= www.xx.com/asp?id=2&y=2009&m=03
url4= www.xx.com/asp?id=2&y=2009&m=03&d=12但是strURL是个变量,有可能有许多个&那我该怎么写呢?  使用if语句来查找每一个&,并把它之前的内容赋值。没找到就跳出。该怎么写呢?希望能写出具体的代码,实在搞不明白。

解决方案 »

  1.   

    CString Find查找到后,再Right截取后面的,然后再循环继续Find,直至找到最后一个&
      

  2.   

    int len = strURL.GetLength();
            char *s= new[len+1];
      strcpy(s,(LPCTSTR)strURL);
            char *d="&";
            char *p;        
            p=strtok(s,d);
            while(p)
            {
              printf("%s\n",s);//输出&前的字符串
              strtok(NULL,d);
            }
      

  3.   

    int len = strURL.GetLength();
            char *s= new[len+1];
      strcpy(s,(LPCTSTR)strURL);
            char *d="&";
            char *p;        
            p=strtok(s,d);
            while(p)
            {
              printf("%s\n",s);
              p = strtok(NULL,d);//上面的代码少了个p
            }
      

  4.   

    CString strURL = _T("www.xx.com/asp?id=2&y=2009&m=03&d=12");
    int nPos = 0;
    CSimpleArray<CString> arStr;
    while ( -1 != (nPos = strURL.Find(_T('&'), nPos))
    {
        CString strTemp = strURL.Left(nPos);
        
        arStr.Add(strTemp);    nPos++;
    }
      

  5.   

    CString strURL = _T("www.xx.com/asp?id=2&y=2009&m=03&d=12");
    int nPos = 0;
    CSimpleArray<CString> arStr; // store string array
    while ( -1 != (nPos = strURL.Find(_T('&'), nPos)))
    {
        CString strTemp = strURL.Left(nPos);
        
        arStr.Add(strTemp);    nPos++;
    }
    arStr.Add(strURL);
      

  6.   

    雪影
    代码好像有错误啊
    syntax error : '['
    syntax error : missing ';' before '{'
    error count exceeds 100; stopping compilation看不懂是哪错了。。