I have a complete URL, say
http://www.mywebsite.com//Folder /Detals /Final Image /La Image Logo.jpg
Here in this NSString, I only want to fetch
[string lastPathComponent]
should do the trick
You can use NSString *string=[[yourString componentsSeparatedByString:@"/"] lastObject]
If it's about the filename in a URL you should definitely create an NSURL
object and query that object for the desired information:
NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com//Folder /Detals /Final Image /La Image Logo.jpg"];
NSString *filename = [url lastPathComponent];
NSURL
is good at parsing URL strings. This way you're sure that you don't get any fragment part ("#anchor") or parameters ("?q=foo&p=bar") in your filename.