Difference between revisions of "Javascript unicode"
From John Freier
(Created page with 'Here is some JavaScript code to convert characters to unicode. function toUnicode(theString) { var unicodeString = ''; for (var i=0; i < theString.length; i++) { var…') |
|||
Line 13: | Line 13: | ||
return unicodeString; | return unicodeString; | ||
} | } | ||
+ | |||
+ | |||
+ | or | ||
+ | |||
+ | Here is a short version, just remember to make sure the length count is 4, adding front 0's | ||
+ | alert("o".charCodeAt(0).toString(16)) |
Latest revision as of 14:05, 12 December 2013
Here is some JavaScript code to convert characters to unicode.
function toUnicode(theString) { var unicodeString = ; for (var i=0; i < theString.length; i++) { var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase(); while (theUnicode.length < 4) { theUnicode = '0' + theUnicode; } theUnicode = '\\u' + theUnicode; unicodeString += theUnicode; } return unicodeString; }
or
Here is a short version, just remember to make sure the length count is 4, adding front 0's
alert("o".charCodeAt(0).toString(16))