ios 刪除url中字段和對應的值

/key - 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;
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章