Noung Noung - 2 months ago 10
Objective-C Question

Objective c Substring

Please help me, I want to Substring like that " http://stackoverflow.com/questions/ask/abc.pdf "
and I want to get " abc.pdf ". It mean I want to get file name of pdf.

Note: it is not the same string.
Forexample : http://stackoverflow.com/questions/ask/abc.pdf,
http://stackoverflow.com/questions/ask/tosf/abc.pdf and sometime http://stackoverflow.com/questions/ask/tosf/12/abc.pdf

Thanks!

Answer

Use the lastPathComponent method of NSURL.

NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/questions/ask/abc.pdf"];
NSString *filename = [url lastPathComponent];