Reputation: 25
i have a kind of input in my program witch users type a link like "http://www.example.com/dd/sa/...../sample.png" and i looking for a code to give me the last section of the link (sample.png)
More accurate:
user type this in a textbox : "http://www.example.com/dd/sa/...../sample.png"
and i receive this : string a = "sample.png"
in other hand i want know all elements after last "/" in my program. i think we can use split() or trim() but i don't know how!
Upvotes: 0
Views: 69
Reputation: 20565
You can use the Path.GetFileName(String)
method
var filename = Path.GetFileName("http://www.example.com/dd/sa/whatever/sample.png");
or
Uri uri = new Uri("http://www.example.com/dd/sa/whatever/sample.png");
var name = uri.Segments[uri.Segments.Length - 1];
Upvotes: 2