美文网首页
Swift 字符串 与 UTF8格式字符串 互转

Swift 字符串 与 UTF8格式字符串 互转

作者: suoluomen | 来源:发表于2018-02-22 18:48 被阅读1237次

    字符串 -> UTF8字符串:

     let imagStr = "https://img.hxdrive.net/uploads/2018/02/20/5a268df93929f33fd5be3ef6a18ced46.10-妻有毒:腹黑大叔宠上天-木瓜 "

    let  imagStr_utf8 = imagStr.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? ""

    UTF8字符串 -> 字符串:

    let urlStr_utf8 = "https://img.hxdrive.net/uploads/2018/02/20/5a268df93929f33fd5be3ef6a18ced46.10-%E5%A6%BB%E6%9C%89%E6%AF%92%EF%BC%9A%E8%85%B9%E9%BB%91%E5%A4%A7%E5%8F%94%E5%AE%A0%E4%B8%8A%E5%A4%A9-%E6%9C%A8%E7%93%9C"

    let urlStr = urlStr_utf8.removingPercentEncoding

    相关文章

      网友评论

          本文标题:Swift 字符串 与 UTF8格式字符串 互转

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