If I have any URL with an image file at the end, such as:
http://www.google.com/image1.jpg
http://www.google.com/test/test23/image1.jpg
And I want to get:
image1.jpg
What is the best way to do this in C#?
string fileName = Path.GetFileName(@"http://www.google.com/test/test23/image1.jpg");
As long as your sure its an image file you can just use the path class.
System.io.path.GetFilenAME
public static void doSomething() {
string url = "http:\\www.google.com\image1.jpg";
string imageFileName = url.Substring( url.LastIndexOf( '\\' ) + 1 );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With