首页 > 代码库 > NSString+URLParser NSScanner

NSString+URLParser NSScanner

@implementation NSString (URLParser)

 

-(NSDictionary*)parserToDict

{

    NSScanner *scanner = [NSScanner scannerWithString:self];

    [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?="]];

    NSString *key;

    NSString *value;

    NSMutableArray *keys = [NSMutableArray new];

    NSMutableArray *vars = [NSMutableArray new];

    [scanner scanUpToString:@"?" intoString:nil]; //ignore the beginning of the string and skip to the vars

    while ([scanner scanUpToString:@"=" intoString:&key]&&[scanner scanUpToString:@"&" intoString:&value]) {

        //[vars addObject:[tempString copy]];

        [keys addObject:key];

        [vars addObject:value];

    }

    

    return [NSDictionary dictionaryWithObjects:vars forKeys:keys];

}

 

@end

NSString+URLParser NSScanner