Reputation: 129
I am getting following characters:
\\u00e2\\u0080\\u0099
from server side and I want to decode this into its correct character which is "`" so please let me know how I can do this in swift.
I don't want to use replace string method as I want a generic solution which should work for all unicode to string conversion.
Thanks,
Upvotes: 2
Views: 3185
Reputation: 1106
If you mean "\\u00e2\\u0080\\u0099"
the string of 18 characters, you have to unescape it to convert these sequences to their actual values.
This is a possible way to do it:
let input = "located in the heart of Wanchai\\u00e2\\u0080\\u0099s Star"
let str = String(data: input.data(using: .utf8)!, encoding: String.Encoding.nonLossyASCII)
This gives "located in the heart of Wanchaiâs Star"
.
As has already been said, "\\u00e2\\u0080\\u0099"
represents a "â"
.
Upvotes: 1