码迷,mamicode.com
首页 > Web开发 > 详细

NSString+URLParser NSScanner

时间:2017-06-14 16:28:16      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:for   har   scan   and   sch   copy   sel   obj   array   

@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

标签:for   har   scan   and   sch   copy   sel   obj   array   

原文地址:http://www.cnblogs.com/feng9exe/p/7008633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!