一个字符串如下
“C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls”
但路径和excel的文件名有可能变化,我想取整个路径最后一个‘\’所在的位置谢谢!

解决方案 »

  1.   

    补充一下:
    如果字符串是
    “C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls”的话,我想要的结果字符串就是这样的
    "C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ"谢谢!
      

  2.   

    try...            string test = @"C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls";
                string path = System.IO.Path.GetDirectoryName(test);
                richTextBox2.Text = path;
      

  3.   


    string file="C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls";
    string filename = file.Substring(filename.LastIndexOf("\\") +1); 
    string filepath = file.Relpace(file,"\\"+filename);//你要的结果
      

  4.   

    string filePath="C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls";
    string path=Path.GetDirectoryName(filePath);PS:path即得
      

  5.   

    Path.GetDirectoryName返回指定路径字符串的目录信息
      

  6.   

    int i = str.LastIndexOf('\');
    string s = str.SubString(0,i);
      

  7.   

    String.LastIndexOf("\")......
    原来还有这个方法。学习到了
    UP下
      

  8.   

    学习到这个方法了。。
    Path.GetDirectoryName
      

  9.   

    int i = str.LastIndexOf('\');
    string s = str.SubString(0,i);