ios 删除url中的某个参数及其对应的值

直接上代码:

-(NSString*)removeParValue:(NSString*)urlStr Key:(NSString*)key{

    //解码
    NSString *decoerurl = [urlStr stringByReplacingOccurrencesOfString:@"+" withString:@" "];
    decoerurl = [decoerurlstringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSArray*array = [decoerurlcomponentsSeparatedByString:@"&"];
    NSMutableString *URLstr = [NSMutableString string];
    NSMutableArray *tempArray = [NSMutableArray arrayWithArray:array];

    [tempArrayenumerateObjectsUsingBlock:^(NSString* obj,NSUIntegeridx,BOOL*stop) {
        if([objhasPrefix:key]) {
            *stop =YES;
            if(*stop ==YES) {
                [tempArrayremoveObject:obj];
            }
        }
    }];

    NSString*par = [[NSString alloc]init];

    for(inti =0; i < tempArray.count; i++)
    {
        if(i !=0) {
            par =@"&";
        }
        [URLstrappendFormat:@"%@%@",pasa,tempArray[i]];
    }
    return  URLstr;
}

你可能感兴趣的:(ios 删除url中的某个参数及其对应的值)