I'm trying to replace some HTML codes in Swift with the appropriate characters. I used a String extension.
extension String {
mutating func fix_HTML_Codes() {
let originalString = self
let newString = originalString.replacingOccurrences(of: "'", with: "\'")
let newString2 = newString.replacingOccurrences(of: """, with: "\"")
self = newString2
}
}
However, instead of replacing my escaped single quote with a single quote, it actually replaces it with \'
, anyone know why?
Here's an example of what I'm getting:
"On which Beatles album would you find the song \'Eleanor Rigby\'?"
It's including the escape character.