Gazzini Gazzini - 1 month ago 10
Swift Question

Remove percent-escaped characters from string

How do I remove, not decode, percent-escaped characters from a string using Swift. For instance:

"hello%20there"

should become
"hellothere"


EDIT:

I would like to replace multiple percent-escaped characters in a string. So:
"hello%20there%0Dperson"

should become
"hellothereperson"

Answer
let string = originalString.replacingOccurrences(of: "%[0-9a-fA-F]{2}", 
                                                 with: "",
                                                 options: .regularExpression, 
                                                 range: nil)