swift

swift中webview的URL带中文或者特殊字符的处理

2016-05-04  本文已影响1312人  桂宁813

letsearchword:String="柴油0#"

/// encodeURIComponent编码方式,会对特殊符号编码

///方法一

//let toSearchword = searchword.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

///方法二

//let toSearchword = CFURLCreateStringByAddingPercentEscapes(nil, searchword, "!*'();:@&=+$,/?%#[]", nil, CFStringBuiltInEncodings.UTF8.rawValue)

/// encodeURI编码,不会对特殊符号编码

lettoSearchword =CFURLCreateStringByAddingPercentEscapes(nil, searchword,nil,"!*'();:@&=+$,/?%#[]",CFStringBuiltInEncodings.UTF8.rawValue)

print(toSearchword)

具体测试网址:http://www.bejson.com/enc/urlencode/

上一篇 下一篇

猜你喜欢

热点阅读