Created
March 11, 2012 12:31
-
-
Save raspo/2016262 to your computer and use it in GitHub Desktop.
Convert string value to unicode via javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional 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