NSString+URLParser NSScanner
Posted zzfx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
URLParser:很实用的URL参数解析器(JAVA代码中方便获取QueryString中的get参数)