Search code examples
objective-ciosnsurl

Fetching part of URL from given URL


Possible Duplicate:
Extract part of URL

How can I fetch part of a url from whole url string?

Example given url:

http://[email protected]:7006/imageID = 45254

Required part:

http://[email protected]:7006

Solution

  • This will work in the general case:

    NSString* str = @"http://[email protected]:7006/imageID=45254";
    NSURL* url = [NSURL URLWithString:str];    
    NSString* aaa = [str stringByReplacingOccurrencesOfString:[url path] withString:@""];