Does anyone know how to convert a unicode to a string in javascript. For instance:
\u2211 -> ∑
\u0032 -> 2
\u222B -> ∫
I basically want to be able to display the symbol in xhtml or html. Haven't decided which I will be using yet.
String str1 = "\u0000"; String str2 = "\uFFFF"; String str1 is assigned \u0000 which is the lowest value in Unicode. String str2 is assigned \uFFFF which is the highest value in Unicode.
Internally in Java all strings are kept in Unicode. Since not all text received from users or the outside world is in unicode, your application may have to convert from non-unicode to unicode.
Unicode is a standard encoding system that is used to represent characters from almost all languages. Every Unicode character is encoded using a unique integer code point between 0 and 0x10FFFF . A Unicode string is a sequence of zero or more code points.
You CAN'T convert from Unicode to ASCII. Almost every character in Unicode cannot be expressed in ASCII, and those that can be expressed have exactly the same codepoints in ASCII as in UTF-8, which is probably what you have.
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.
Just found a way: String.fromCharCode(parseInt(unicode,16))
returns the right symbol representation. The unicode here doesn't have the \u
in front of it just the number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With