如果我在结尾处有任何带有图像文件的URL,例如:
http://www.google.com/image1.jpg
http://www.google.com/test/test23/image1.jpg
我想得到:
image1.jpg
在C#中执行此操作的最佳方法是什么?
答案 0 :(得分:24)
string fileName = Path.GetFileName(@"http://www.google.com/test/test23/image1.jpg");
答案 1 :(得分:5)
只要您确定它的图像文件,您就可以使用路径类。
答案 2 :(得分:1)
public static void doSomething() {
string url = "http:\\www.google.com\image1.jpg";
string imageFileName = url.Substring( url.LastIndexOf( '\\' ) + 1 );
}
答案 3 :(得分:1)
不是最好的,但肯定是一种方式
url = "blahblah\image1.jpg"
string imageName = url.substring(url.lastindexof("\") + 1);