Converting unicode character to string format

后端 未结 5 2207
失恋的感觉
失恋的感觉 2020-11-30 07:44

Does anyone know how to convert a unicode to a string in javascript. For instance:

\\u2211 -> ∑ \\u0032 -> 2 \\u222B -> ∫

5条回答
  •  时光说笑
    2020-11-30 07:57

    A function from k.ken's response:

    function unicodeToChar(text) {
       return text.replace(/\\u[\dA-F]{4}/gi, 
              function (match) {
                   return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
              });
    }
    

    Takes all unicode characters in the inputted string, and converts them to the character.

提交回复
热议问题