URL取参

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取参)