views:

40

answers:

3

I have an URL and need to extract a part of it.

The url is like this:
http://website.com/get.php?url=http://www.website2.com/index.html?articleID=123456

And I need to extract this part:
http://www.website2.com/index.html?articleID=123456

How would I do this in Objective-C?

+1  A: 

See the NSString -rangeOfSubstring: and -componentsSeparatedByString: methods.

In this case, you could just split the string at the "=".

NSResponder
+1  A: 

First of all, create a NSURL. Then, use the querymethod to get the query string part:

NSURL    * url = [ NSURL URLWithString: @"... your url ..." ];
NSString * q   = [ url query ];

Then you can use the NSString methods to isolate the needed part.

Macmade
Thanks, now I get: url=http://www.website2.com/index.html?articleID=123456 How can I remove the "url=" ?
mofle
As NSResponder said, now you can use rangeOfSubstring and componentsSeparatedByString methods. Take a look at the documentation: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
Macmade
A: 

See below URL

http://monotouch.pastebin.com/jFBuapZY

Yogi
The question was for Objective-C
Macmade