Ascii unicode string codes to utf8 in javascript -


i have string containing unicodes , i'd transform them utf8. how implement ->

input:

var data = "\u03b1" // coming python remote callback data var html = "letter a: " + data document.getelementbyid('input').innerhtml = html 

output on div#input is:

letter a: \u03b1 

but should be:

letter a: α 

i suspect because "\u03b1" not written on javascript code, passed via text variable python, javascript engine doesn't transform characters correct form, keeps them strings.

i found answer from: converting unicode character string format

function unicodetochar(text) {     return text.replace(/\\u[\da-fa-f]{4}/g,          function (match) {             return string.fromcharcode(parseint(match.replace(/\\u/g, ''), 16));         }); } 

applying in case:

var html = "letter a: " + unicodetochar(data) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -