iPhone开发之NSURL

通过一个URL,获取URL中包含的各种信息。例如:

 NSURL *url = [NSURL URLWithString:
@"http://some-site.com:999/dir1/dir2;param?field-1=value-1&field-2=value-2#anchor1"];

NSLog(@"Scheme: %@", [url scheme]); //方案
NSLog(@"Host: %@", [url host]); //主机
NSLog(@"Port: %@", [url port]); //端口
NSLog(@"Path: %@", [url path]); //路径
NSLog(@"Relative path: %@", [url relativePath]); //相关路径
NSLog(@"Path components as array: %@", [url pathComponents]); //路径的每个组成部分
NSLog(@"Parameter string: %@", [url parameterString]); //参数
NSLog(@"Query: %@", [url query]); //查询
NSLog(@"Fragment: %@", [url fragment]); //分段

得到的结果:



原文地址:https://www.cnblogs.com/foxmin/p/2405129.html