我从简书搬家啦~~
本篇文章源地址:https://www.jianshu.com/p/397acacbd90d
相信大家总会碰到需要encode的时候,接着百度啊,然后发现stringByAddingPercentEscapesUsingEncoding这个方法,但是这个方法有时候无法对+等符号进行encode。那这时候咋办呢?
//encode
CF_EXPORT
CFStringRef CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding);
NSString *encodedValue = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(nil,(CFStringRef)value, nil,(CFStringRef)@"!*'();:@&=+$,/ %#[]", kCFStringEncodingUTF8));