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

匆匆过客 提交于 2019-12-02 03:22:46

问题


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

La Image Logo.jpg

How can I do so?

Thanks


回答1:


[string lastPathComponent] should do the trick




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/20267826/how-to-take-nsstring-after-specific-character-which-occurs-multiple-time-in-nsst

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!