cocoaswift4.2

Decoding Percent-Encoded String in Swift 4.2?


I'm trying to decode a percent-encoded string but can't figure out how to. For example:

let str = "Hello%20World"

// I want to decode 'str' to 'Hello World'

Does anyone know the best way to do this in Swift 4.2? Thank you.


Solution

  • To remove percent encoding, I would call the removingPercentEncoding method.

    https://developer.apple.com/documentation/foundation/nsstring/1409569-removingpercentencoding