我有一个string path = c:\inetpub\wwwrroot\images\pdf\admission.pdf
我正在用这个
path = path.LastIndexOf("\\").ToString();
path = path.Substring(path.LastIndexOf("/") + 1);
我想得到:
c:\inetpub\wwwrroot\images\pdf
c:\inetpub\wwwrroot\images\pdf\admission.pdf
现在我想从这个字符串路径
获取admission.pdf,我该怎么做?
最佳答案
string path = "c:\\inetpub\\wwwrroot\\images\\pdf\\admission.pdf";
string folder = path.Substring(0,path.LastIndexOf(("\\")));
// this should be "c:\inetpub\wwwrroot\images\pdf"
var fileName = path.Substring(path.LastIndexOf(("\\"))+1);
// this should be admin.pdf
关于c# - 如何从 C# 中的文件路径获取子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5127150/