0

I am receiving from backend the string "something \xe9 something else" and I would like to convert it to "something é something else".

I've done some search on that and haven't found anyone else with this same problem, however I came up with the following that worked for me:

function decode(str){
    return eval('"' + str + '"');
}
  • If I understand correctly this questions has nothing to do with UTF-8 or ISO 8859-1, you're simply trying to convert \x escape sequences in your strings back into the corresponding characters. Perhaps the answers here will help: https://stackoverflow.com/questions/34056509/javascript-x-escaping – skirtle Sep 11 '17 at 19:05
  • 1
    Like @skirtle, this is not a utf8 issue, instead of eval `JSON.parse('"something \xe9 something else"')` might be less resource hungry. – Keith Sep 11 '17 at 19:13

0 Answers0