1

I have a NSURL String:

NSString *url = @"http://ht21.easou.com/mty_ZhiQianQT.mp3?src=test&name=mty&size=100";

What is the quickest way to get the substring mty_ZhiQianQt.mp3?

4

2 回答 2

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

于 2012-05-17T09:41:43.273 回答
1

子字符串 Nsstring 有很多方法。您可以使用范围进行子字符串化。请参考 Nsstring 类参考。

http://mobiledevelopertips.com/cocoa/nsrange-and-nsstring-objects.html

http://iphonesdkbasics.blogspot.in/2010/07/easy-nsstring-substring.html

于 2012-05-17T09:27:27.880 回答