[英]Objective c Substring
请帮帮我,我想要Substring这样的“ https://stackoverflow.com/questions/ask/abc.pdf ”,我想获取“ abc.pdf ”。 这意味着我要获取pdf的文件名。
注意:它不是相同的字符串。 Forexample: https://stackoverflow.com/questions/ask/abc.pdf , https://stackoverflow.com/questions/ask/tosf/abc.pdf和某个https://stackoverflow.com/questions/ask/tosf /12/abc.pdf
谢谢!
使用NSURL的lastPathComponent
方法。
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/questions/ask/abc.pdf"];
NSString *filename = [url lastPathComponent];
除了Rijo回答。 无需创建NSURL
实例,可以使用NSString
lastPathComponent
方法:
NSString *filename = [@"http://stackoverflow.com/questions/ask/abc.pdf" lastPathComponent];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.