Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从图像url解析出图像名称_C#_Url - Fatal编程技术网

C# 如何从图像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

如果我有任何在末尾带有图像文件的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.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);