Skip to content

Instantly share code, notes, and snippets.

@edfuh
Created October 8, 2011 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edfuh/1271740 to your computer and use it in GitHub Desktop.
Save edfuh/1271740 to your computer and use it in GitHub Desktop.
convert characters to their unicode equivalents
function toUnicode(str) {
var unicodeStr = '',
i = 0,
strlen = str.length,
theUnicode;
for (; i < strlen; i++) {
code = str.charCodeAt(i).toString(16).toUpperCase();
while (code.length < 4) {
code = '0' + code;
}
code = '\\u' + code;
unicodeStr += code;
}
return unicodeStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment