tags:

views:

53

answers:

4

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

+1  A: 

See the NSString class reference. Methods which are likely to be of interest to you include rangeOfString, componentsSeparatedByString, substringFromIndex, and substringToIndex

William Jockusch
A: 

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;
brutella
+2  A: 

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:

http://developer.apple.com/library/mac/#documentation/cocoa/reference/Foundation/Classes/NSURL_Class/Reference/Reference.html

Josh Hinman
lak in iphone
Josh Hinman
how to pass parameters to this query method
lak in iphone
A: 

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]

Ben