问题
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:
First of all, create a NSURL. Then, use the query
method 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.
回答2:
See the NSString
-rangeOfSubstring:
and -componentsSeparatedByString:
methods.
In this case, you could just split the string at the "=".
来源:https://stackoverflow.com/questions/3308681/extract-part-of-url