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…') |
(No difference)
|
Revision as of 14:04, 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; }