有一个路径如下:
c:\\1\\2\\3\\4\\5
现在要把这个路径拆开,拆成一个一个的路径。
c:\\1
c:\\1\\2
c:\\1\\2\\3
c:\\1\\2\\3\\4
c:\\1\\2\\3\\4\\5
请大家给出一个实现方法

解决方案 »

  1.   

    先找到第一个'\\'
    p=strchr(buf,'\\');
    p='\0';
    len = strlen(buf);
    p = '\\';
    memcpy(buf,buf1,len);这样你就把第一个拷贝到buf1里了
    接着继续找
      

  2.   

    CString strPath = "c:\\1\\2\\3\\4\\5";
    int nPos = 0;while(strPath.Find("\\",nPos) > -1)
    {
        nPos = strPath.Find("\\");
        TRACE(strPath.Left(nPos));// 或用变量保存
        nPos++;
    }临时写了个,不知道是不是你想要的
      

  3.   

    void GetPath(CString str, CStringArray& arr)
    {
    CString strTemp;
    int nIndex = 0;
    strTemp = str;
    arr.RemoveAll();
    while( (nIndex = strTemp.Find('\\', nIndex)) != -1 )
    {
    arr.Add(str.Left(nIndex));
    nIndex++;
    }
    arr.RemoveAt(0);
    arr.Add(str);
    }调用方法
    CString strPath = "c:\\1\\2\\3\\4\\5";
    CStringArray arrPath;
    GetPath(strPath, arrPath);arrPath[0]
    arrPath[1]
    arrPath[2]
    arrPath[3]
    arrPath[4]
    为结果