Kaibin
Kaibin

Reputation: 474

get an special substring from NSURL string

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?

Upvotes: 1

Views: 662

Answers (2)

Hector
Hector

Reputation: 3907

Try this :

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 

just for your information :

NSLog(@"%@",url.scheme); // http
NSLog(@"%@",url.host); // ht21.easou.com
NSLog(@"%@",url.lastPathComponent); // mty_ZhiQianQT.mp3

Upvotes: 3

Mangesh
Mangesh

Reputation: 2285

There is lots of methods for substring Nsstring. You can substring with range. Please refer Nsstring class reference for same.

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

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

Upvotes: 1

Related Questions