How to extract scheme and host of a URL once?

China☆狼群 提交于 2019-12-08 09:23:15

问题


Imagine this is my URL

NSURL *theURL=[NSURL URLWithString:@"http://stackoverflow.com/questions/ask"];

How can i extract only:

http://stackoverflow.com

?


回答1:


How about [NSString stringWithFormat:@"%@://%@", [theURL scheme], [theUrl host]]




回答2:


Have you tried [theURL host]?



来源:https://stackoverflow.com/questions/8890475/how-to-extract-scheme-and-host-of-a-url-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!