1.URL 含有中文
用sdwebimage 加载图片加载不出来,打印发现URL中有中文
解决方案
url 转换一下
+(NSString *)stringChangeChineseTransformWithUrlString:(NSString*)string{
return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#^{}\"[]|\\<> "].invertedSet];
}
2.URL 含有乱码
http://xxx.xxx.xxx.com?name=E5%BC%A0%E7%91%B6
需求是拿到name后面的名称,用 utf8不好用
解决方案
+(NSString *)StringDecodeChangeForChineseWithString:(NSString *)str{
NSMutableString *resultStr = [NSMutableString stringWithString:str];
[resultStr replaceOccurrencesOfString:@"+" withString:@" " options:NSLiteralSearch range:NSMakeRange(0,[resultStr length])];
return [resultStr stringByRemovingPercentEncoding];;
}
网友评论