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

后端 未结 3 1973
南笙
南笙 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:38

    [string lastPathComponent] should do the trick

    0 讨论(0)
  • 2021-01-22 04:38

    You can use NSString *string=[[yourString componentsSeparatedByString:@"/"] lastObject]

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题