How to take NSString after specific character which occurs multiple time in NSString?

后端 未结 3 1985
南笙
南笙 2021-01-22 04:31

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

3条回答
  •  离开以前
    2021-01-22 04:45

    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.

提交回复
热议问题