补充一下: 如果字符串是 “C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls”的话,我想要的结果字符串就是这样的 "C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ"谢谢!
try... string test = @"C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls"; string path = System.IO.Path.GetDirectoryName(test); richTextBox2.Text = path;
如果字符串是
“C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls”的话,我想要的结果字符串就是这样的
"C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ"谢谢!
string path = System.IO.Path.GetDirectoryName(test);
richTextBox2.Text = path;
string file="C:\Documents and Settings\10015381.QINGDAOTRE\デスクトップ\評価結果100.xls";
string filename = file.Substring(filename.LastIndexOf("\\") +1);
string filepath = file.Relpace(file,"\\"+filename);//你要的结果
string path=Path.GetDirectoryName(filePath);PS:path即得
string s = str.SubString(0,i);
原来还有这个方法。学习到了
UP下
Path.GetDirectoryName
string s = str.SubString(0,i);