Reputation: 665
I am trying to parse a HTML string in a iPhone app.
Example: The URL is http://www.apple.com/developer
I want to delete the "developer" part so all I have will be http://www.apple.com
How could I do this?
Upvotes: 0
Views: 248
Reputation: 5960
Have you considered the NSUrl
method URLByDeletingLastPathComponent
or the method pathComponents
?
URLByDeletingLastPathComponent
Returns a new URL made by deleting the last path component from the original URL.
pathComponents
Returns the individual path components of a file URL in an array.
Here is a good tutorial/example on NSURL
methods.
Upvotes: 0
Reputation: 81082
You can also bring it in to an NSURL
and get the parts you want:
NSURL *url = [NSURL URLWithString:@"http://www.apple.com/developer"];
[url host]; // @"www.apple.com"
[url scheme]; // @"http"
Upvotes: 4
Reputation: 12710
You can search for the third slash in the string and then substring it to get the part you want
Upvotes: 0