码迷,mamicode.com
首页 > 其他好文 > 详细

图片地址含有中文的编码

时间:2017-09-12 13:34:56      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:def   pre   4.0   esc   nil   ret   test   odi   min   

Swift
let str : NSString = CFURLCreateStringByAddingPercentEscapes(nil, dic, "!*‘();:@&=+$,/?%#[]" as CFString, nil, CFStringBuiltInEncodings.UTF8.rawValue) // let str : NSString = dic.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! as NSString // let str : NSString = dic.addingPercentEscapes(using: String.Encoding.utf8.rawValue)! // let str : NSString = dic.addingPercentEncoding(withAllowedCharacters: NSCharacterSet(charactersIn:"`#%^{}\"[]|\\<> ").inverted)!

 

OC

//编码
- (NSString *)encode {
    CFStringRef strRef = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, NULL, kCFStringEncodingUTF8);
    return (NSString *)CFBridgingRelease(strRef);
}

 

经过上面的编码即可加载出图片

 

 

图片地址含有中文的编码

标签:def   pre   4.0   esc   nil   ret   test   odi   min   

原文地址:http://www.cnblogs.com/HMJ-29/p/7509371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!