Swift学习

Swift4.0 URLString内有汉字转码方法

2018-02-03  本文已影响1603人  mqhong

2018年2月3日星期六


        let str = "https://www.baidu.com/s?wd=点个赞吧"
        //返回查询URL组件中允许使用的字符的字符集。
        let fuck = str.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
        let ooo = fuck?.removingPercentEncoding
        //通过用匹配的UTF-8字符替换所有百分比编码序列
        //从字符串中创建一个新字符串。
        print(ooo)//解码后 又是包含汉字的咯
上一篇 下一篇

猜你喜欢

热点阅读