Javascript unicode
From John Freier
Revision as of 14:04, 12 December 2013 by Jfreier (Talk | contribs) (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…')
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;
}