URL取参

作者: Bonucci | 来源:发表于2017-03-06 18:19 被阅读0次

1,取参方法

-(NSString *)fetchUrlParam:(NSString *)param url:(NSString *)url {

NSError *error;

NSString *regTags=[[NSString alloc] initWithFormat:@"(^|&|\\?)+%@=+([^&]*)(&|$)",param];

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regTags

options:NSRegularExpressionCaseInsensitive

error:&error];

// 执行匹配的过程

NSArray *matches = [regex matchesInString:url

options:0

range:NSMakeRange(0, [url length])];

for (NSTextCheckingResult *match in matches) {

return [url substringWithRange:[match rangeAtIndex:2]];

}

return nil;

}

2,使用

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

[super touchesBegan:touches withEvent:event];

NSURL *url = [NSURL URLWithString:@"yqsAppScheme://www.yqsapp.com:80/invitationiInfo"];

NSLog(@"--------%@------path === %@------",s,[url path],[url pathComponents]);

}

相关文章

网友评论

      本文标题:URL取参

      本文链接:https://www.haomeiwen.com/subject/zmlrgttx.html