url 特殊字符处理

#pragma mark 发送url字符替换特殊字符  这里必须先替换%  %25
+ (NSString *)URLreplacewithCharacter:(NSString *)aUrlString//URL转义字符
{
    NSString *tempStr = [NSString stringWithFormat:@"%@",aUrlString];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"%" withString:@"%25"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"#" withString:@"%23"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
    tempStr = [tempStr stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
    return tempStr;
}

这里要注意 % 号要先替换 否则你懂的~~

你可能感兴趣的:(url 特殊字符处理)