user1227928
user1227928

Reputation: 829

Fetching the string from NSURL

I have a NSURL

NSURL* url = [NSURL URLWithString:@"http://www.google.com"];

I want to get the "google" from this string , How can i do that?

Upvotes: 2

Views: 2974

Answers (1)

Jon Grant
Jon Grant

Reputation: 11530

You can get just the domain part with this:

[url host]

...will get you www.google.com, then you'll need to do some regex/string replacement to strip off the www. and .com parts.

I'd suggest a regex something like the following:

\.?(.+)\.([a-z]{2,})$

...then pull out that first match for the part you want.

Upvotes: 6

Related Questions