我有一个NSURL
字符串:
NSString *url = @"http://ht21.easou.com/mty_ZhiQianQT.mp3?src=test&name=mty&size=100";
获取子串mty_ZhiQianQt.mp3
的最快捷方式是什么?
答案 0 :(得分:3)
试试这个:
NSURL* url = [NSURL URLWithString:@"http://ht21.easou.com/mty_ZhiQianQT.mp3?src=test&name=mty&size=100"];
NSString *name =[NSString stringWithFormat:@"%@",[url.pathComponents objectAtIndex:1]];
NSLog(@"%@",name); // mty_ZhiQianQT.mp3
仅供参考:
NSLog(@"%@",url.scheme); // http
NSLog(@"%@",url.host); // ht21.easou.com
NSLog(@"%@",url.lastPathComponent); // mty_ZhiQianQT.mp3
答案 1 :(得分:1)
子串Nsstring有很多方法。您可以使用范围子字符串。请参考Nsstring类引用。
http://mobiledevelopertips.com/cocoa/nsrange-and-nsstring-objects.html
http://iphonesdkbasics.blogspot.in/2010/07/easy-nsstring-substring.html