iOS中对字符串汉字进行UTF-8编码:输出str字符串的UTF-8格式
[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
解码:把str字符串以UTF-8规则进行解码
[str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
但是现在以上两个方法在9.0已经分离了,现在会出现一些黄色警告,这对于有洁癖的程序员是受不了的,但是对应的替代方法:
编码:
[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
解码:
[str stringByRemovingPercentEncoding];