-
-
let str = "https://www.baidu.com/s?wd=点个赞吧" //返回查询URL组件中允许使用的字符的字符集。
-
let fuck = str.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-
-
-
上面代码中 fuck既是转换后的url,而且这种转换不是吧https后面的几个://也一并给转换了。等有机会再把CharacterSet中的参数介绍一遍
-
顺带附送一个url转码后解码的方法吧
let ooo = fuck?.removingPercentEncoding
//通过用匹配的UTF-8字符替换所有百分比编码序列
//从字符串中创建一个新字符串。
print(ooo)//解码后 又是包含汉字的咯