繁体   English   中英

目标c子字符串

[英]Objective c Substring

请帮帮我,我想要Substring这样的“ https://stackoverflow.com/questions/ask/abc.pdf ”,我想获取“ abc.pdf ”。 这意味着我要获取pdf的文件名。

注意:它不是相同的字符串。 Forexample: https://stackoverflow.com/questions/ask/abc.pdfhttps://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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM