nsurl 網址拆解


NSURL *url = [NSURL URLWithString:@"http://www.test.com/member/index.php?name=cat&age=6"];
NSLog(@"%@", url.scheme); // http
NSLog(@"%@", url.host); // www.test.com
NSLog(@"%@", url.path); // /member/index.php
if ([url.pathComponents count] >= 2) {
NSLog(@"%@", [url.pathComponents objectAtIndex:1]); // member
}
NSLog(@"%@", url.lastPathComponent); // index.php

子網域以及傳入的參數要自行處理。

發表迴響