2

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.