[英]How to take NSString after specific character which occurs multiple time in NSString?
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 在这个NSString中,我只想获取
La Image Logo.jpg
How can I do so? 我该怎么办?
Thanks 谢谢
[string lastPathComponent]
应该可以解决问题
If it's about the filename in a URL you should definitely create an NSURL
object and query that object for the desired information: 如果是关于URL中的文件名的,那么您绝对应该创建一个NSURL
对象,并在该对象中查询所需的信息:
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. NSURL
擅长解析URL字符串。 This way you're sure that you don't get any fragment part ("#anchor") or parameters ("?q=foo&p=bar") in your filename. 这样,您可以确定文件名中没有任何片段部分(“ #anchor”)或参数(“?q = foo&p = bar”)。
您可以使用NSString *string=[[yourString componentsSeparatedByString:@"/"] lastObject]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.