NSURL 子串截取

NSURL *url = [NSURL URLWithString:@"http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163navi&regPage=163"];
    
    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]);
    
    NSLog(@"User: %@", [url user]);
    
    NSLog(@"Password: %@", [url password]);

打印结果:

2016-04-21 14:15:27.929 NSURLtestDemo[2658:107786] Scheme: http
2016-04-21 14:15:27.929 NSURLtestDemo[2658:107786] Host: reg.email.163.com
2016-04-21 14:15:27.929 NSURLtestDemo[2658:107786] Port: (null)
2016-04-21 14:15:27.929 NSURLtestDemo[2658:107786] Path: /unireg/call.do
2016-04-21 14:15:27.929 NSURLtestDemo[2658:107786] Relative path: /unireg/call.do
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] Path components as array: (
    "/",
    unireg,
    "call.do"
)
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] Parameter string: (null)
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] Query: cmd=register.entrance&from=163navi&regPage=163
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] Fragment: (null)
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] User: (null)
2016-04-21 14:15:27.930 NSURLtestDemo[2658:107786] Password: (null)

需要对URL部分子串进行比较,需要截取其中一些字段,这种方式比较直观。

posted @ 2016-04-21 14:20  小屁孩~  阅读(829)  评论(0编辑  收藏  举报