Skip to content

Instantly share code, notes, and snippets.

@MgenGlder
Created March 14, 2017 15:43
Show Gist options
  • Save MgenGlder/87459553e8a7626eeb7d3fe91634bf94 to your computer and use it in GitHub Desktop.
Save MgenGlder/87459553e8a7626eeb7d3fe91634bf94 to your computer and use it in GitHub Desktop.
Convert string to string with unicode characters
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment