i hav a url and want to extract part of the string ...
i hav url like www.google.com?id=10&jkhsds=fg.php
i want to extract the value of id
i hav a url and want to extract part of the string ...
i hav url like www.google.com?id=10&jkhsds=fg.php
i want to extract the value of id
See the NSString class reference. Methods which are likely to be of interest to you include rangeOfString, componentsSeparatedByString, substringFromIndex, and substringToIndex
You can access the string through the absoluteString
property of the NSURL
class. Then you can extract some parts from the string with methods like
- (NSString *)substringFromIndex:(NSUInteger)anIndex;
- (NSString *)substringToIndex:(NSUInteger)anIndex;
- (NSString *)substringWithRange:(NSRange)aRange;
If you create an NSURL
object, like so:
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
You can use the methods of the NSURL
object to get whatever you need, e.g. scheme
, host
, port
, path
, and query
.
See here:
You might be able to get exactly what you want from various properties of the NSURL class such as baseURL,host,path,query etc...
If your URL is an NSString you can create an NSURL with [NSURL URLWithString:string]