string a="C:\\abc\\def\\gh"
按返回上一层的时候得出
a="C:\\abc\\def"

解决方案 »

  1.   

    你就按\\分隔,然后放到一个栈里就行了,按一下返回,就pop一次,然后把pop出来的从a中删除
      

  2.   

    只有30分...
     string a = "C:\\abc\\def\\gh";1字符串截取
    a = a.Substring(0, a.LastIndexOf('\\'));2 使用FileInfo
    a = new FileInfo(a).Directory.FullName;3 使用 DirectoryInfo
    a = new DirectoryInfo(a).Parent.FullName;
      

  3.   

    string a="C:\\abc\\def\\gh"
    按返回上一层的时候得出
    a="C:\\abc\\def"
    用\\substring,进栈,每次出栈,出栈的内容进另一个栈。
    不但可以返回上一层,还可以回到刚才一层~