美文网首页
URLEncode和URLDecode

URLEncode和URLDecode

作者: 开洋_shen | 来源:发表于2018-05-17 13:14 被阅读0次

URLEncode

extension String {
// URL Decode
func URLDecode() -> String? {
return self.stringByRemovingPercentEncoding // stringByReplacingPercentEscapesUsingEncoding is deprecated
}

// URL Encode
func URLEncode() -> String? {
    return self.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet(charactersInString: "!*'\"();:@&=+$,/?%#[]% ").invertedSet) // `CFURLCreateStringByAddingPercentEscapes` is deprecated
}

}

URLDecode

url.absoluteString.stringByRemovingPercentEncoding

相关文章

网友评论

      本文标题:URLEncode和URLDecode

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