Objective-C Substring
I'd like to know how to grab everything inbetween http:// and /
NOTE: The IP address will change depending on environments and it may be a hostname instead of an IP address. I need to be able to handle both.
e.g.,
http://127.0.0.1/foo/开发者_如何学Gobar/chocolate
Output:
http://127.0.0.1
That looks like a URL. Why not use something like
[[NSURL URLWithString:theString] host]
That will return the hostname part of the URL, which in your example is 127.0.0.1
. If you actually need a full URL that contains just the host, you could also try something like
[[NSURL URLWithString:"/" relativeToURL:[NSURL URLWithString:theString]] absoluteURL]
精彩评论