C# 如何从图像url解析出图像名称
如果我有任何在末尾带有图像文件的URL,例如:C# 如何从图像url解析出图像名称,c#,url,C#,Url,如果我有任何在末尾带有图像文件的URL,例如: http://www.google.com/image1.jpg http://www.google.com/test/test23/image1.jpg 我想得到: image1.jpg 在C#中实现这一点的最佳方法是什么?只要您确定它是一个图像文件,就可以使用path类 不是最好的,但肯定是一种方式 url = "blahblah\image1.jpg" string imageName = url.substring(url.last
http://www.google.com/image1.jpg
http://www.google.com/test/test23/image1.jpg
我想得到:
image1.jpg
在C#中实现这一点的最佳方法是什么?只要您确定它是一个图像文件,就可以使用path类
不是最好的,但肯定是一种方式
url = "blahblah\image1.jpg"
string imageName = url.substring(url.lastindexof("\") + 1);
URL使用前斜杠。这真的是输入的样子吗?@matthewflaschen-typoCapitalization-issue。应该是System.IO.Path.GetFileName(Path)这基本上就是Path.GetFileName所做的事情Yup同时使用前斜杠和后斜杠-比我的答案更好。
public static void doSomething() {
string url = "http:\\www.google.com\image1.jpg";
string imageFileName = url.Substring( url.LastIndexOf( '\\' ) + 1 );
}
url = "blahblah\image1.jpg"
string imageName = url.substring(url.lastindexof("\") + 1);