美文网首页
iOS utf-8全编码问题

iOS utf-8全编码问题

作者: 王家小雷 | 来源:发表于2019-03-14 15:02 被阅读0次
  • (NSString )stringByAddingPercentEscapesUsingEncodingExt:(NSStringEncoding)enc stringWith:(NSString )str
    {
    if([str respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)] == YES)
    {
    NSCharacterSet
    set = [[NSCharacterSet characterSetWithCharactersInString:@"!
    '();:@&=+$,/?%#[]"] invertedSet];
    return [str stringByAddingPercentEncodingWithAllowedCharacters:set];
    }
    else
    {

pragma clang diagnostic push

pragma clang diagnostic ignored "-Wdeprecated-declarations"

// NSString * newString = (__bridge_transfer NSString *)
NSString * newString = ( NSString )
CFURLCreateStringByAddingPercentEscapes(NULL,
(__bridge CFStringRef)str,
NULL,
(CFStringRef)@"!
'();:@&=+$,/?%#[]",
CFStringConvertNSStringEncodingToEncoding(enc));

pragma clang diagnostic pop

    return newString;
}

}

调用
content = [self stringByAddingPercentEscapesUsingEncodingExt:NSUTF8StringEncoding stringWith:content];

相关文章

网友评论

      本文标题:iOS utf-8全编码问题

      本文链接:https://www.haomeiwen.com/subject/dpaqmqtx.html