I need to parse a URL string like this one:
&ad_eurl=http://www.youtube.com/video/4bL4FI1Gz6s&hl=it_IT&iv_logging_level=3&ad_flags=0&ends
- (NSString *)getLoginTokenFromUrl:(NSString *)urlString {
NSURL *url = [NSURL URLWithString:urlString];
NSArray *queryStrings = [url.query componentsSeparatedByString:@"&"];
NSMutableDictionary *queryParams = [[NSMutableDictionary alloc] init];
for (NSString *qs in queryStrings) {
// Get the parameter name
NSArray *components = [qs componentsSeparatedByString:@"="];
NSString *key = [components objectAtIndex:0];
// Get the parameter value
NSString *value;
if (components.count > 1) {
value = [components objectAtIndex:1];
}
else {
value = @"";
}
value = [value stringByReplacingOccurrencesOfString:@"+" withString:@" "];
value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
queryParams[key] = value;
}
return [queryParams objectForKey:@"login_token"];
}