Are there any standard objects or functions to parse an NSURL\'s components? Clearly I could write one, but why re-invent the wheel?
[NSURL path] will
Heres what i use to parse the query string
// Parse the individual parameters
// parameters = @"hello=world&foo=bar";
NSMutableDictionary *dictParameters = [[NSMutableDictionary alloc] init];
NSArray *arrParameters = [parameters componentsSeparatedByString:@"&"];
for (int i = 0; i < [arrParameters count]; i++) {
NSArray *arrKeyValue = [[arrParameters objectAtIndex:i] componentsSeparatedByString:@"="];
if ([arrKeyValue count] >= 2) {
NSMutableString *strKey = [NSMutableString stringWithCapacity:0];
[strKey setString:[[[arrKeyValue objectAtIndex:0] lowercaseString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
NSMutableString *strValue = [NSMutableString stringWithCapacity:0];
[strValue setString:[[[arrKeyValue objectAtIndex:1] stringByReplacingOccurrencesOfString:@"+" withString:@" "] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
if (strKey.length > 0) [dictParameters setObject:strValue forKey:strKey];
}
}
NSLog(@"Parameters: %@", dictParameters);