如何从图片网址中解析出图片名称

leo*_*ora 9 c# url

如果我在末尾有任何带有图像文件的URL,例如:

http://www.google.com/image1.jpg
http://www.google.com/test/test23/image1.jpg
Run Code Online (Sandbox Code Playgroud)

我想得到:

image1.jpg
Run Code Online (Sandbox Code Playgroud)

在C#中执行此操作的最佳方法是什么?

Fre*_*lad 25

string fileName = Path.GetFileName(@"http://www.google.com/test/test23/image1.jpg");
Run Code Online (Sandbox Code Playgroud)

  • Yup适用于前进和后退斜线 - 这样我的答案就更好了. (2认同)

rer*_*run 5

只要您确定它的图像文件,您就可以使用路径类.

System.io.path.GetFilenAME