NSURLComponents能夠很方便地把URL分爲幾個部分ios
//1.取出url的某部分 NSString *url = @"http://en.wikipedia.org/wiki/Special:Search?search=ios"; NSURLComponents *components = [NSURLComponents componentsWithString:url]; NSString *host = components.host; NSLog(@"%@",host); //en.wikipedia.org //2.修改url components.host = @"www.baidu.com"; NSURL *esURL = [components URL]; NSLog(@"%@",esURL);//http://www.baidu.com/wiki/Special:Search?search=ios