Swift - encode URL

后端 未结 17 1892
無奈伤痛
無奈伤痛 2020-11-21 22:20

If I encode a string like this:

var escapedString = originalString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)

it does

17条回答
  •  伪装坚强ぢ
    2020-11-21 23:01

    Swift 3:

    let allowedCharacterSet = (CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[] ").inverted)
    
    if let escapedString = originalString.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) {
    //do something with escaped string
    }
    

提交回复
热议问题