一个URL示例https://johnny:p4ssw0rd@www.example.com:443/diandi86/gogo?id=123456&name=Jack#reference
代码如下
NSString *strUlr = @"https://johnny:p4ssw0rd@www.example.com:443/diandi86/gogo?id=123456&name=Jack#reference";
self.urlLabel.text = strUlr;
NSURL *tempUrl = [NSURL URLWithString:strUlr];
self.schemeLabel.text = [NSString stringWithFormat:@"scheme:%@",[tempUrl scheme]];
self.userLabel.text = [NSString stringWithFormat:@"user:%@",[tempUrl user]];
self.passwordLabel.text = [NSString stringWithFormat:@"password:%@",[tempUrl password]];
self.hostLabel.text = [NSString stringWithFormat:@"host:%@",[tempUrl host]];
self.portLabel.text = [NSString stringWithFormat:@"port:%@",[tempUrl port]];
self.pathLabel.text = [NSString stringWithFormat:@"path:%@",[tempUrl path]];
self.queryLabel.text = [NSString stringWithFormat:@"query:%@",[tempUrl query]];
self.fragmentLabel.text = [NSString stringWithFormat:@"fragment:%@",[tempUrl fragment]];
主界面如下

点击URL解析,跳转到URL解析界面
URL解析界面如下

网友评论