Created
May 15, 2011 01:11
-
-
Save timothyarmstrong/972798 to your computer and use it in GitHub Desktop.
Convert a string to a function call that puts together that string form character codes
This file contains 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
/** | |
* Convert a string to a function call that puts together that string form character codes. | |
* Useful when you are trying to avoid using quotation characters in JavaScript (because they | |
* are being escaped) but you still want to use a string. | |
* | |
* @author Timothy Armstrong | |
* @param str String The string you want to convert | |
* @return String The JavaScript code that can replace your string | |
*/ | |
function toChars(str) { | |
var out = 'String.fromCharCode('; | |
for (var i = 0; i < str.length; i++) { out += str.charCodeAt(i) + ',' } | |
return out.substr(0,out.length-1) + ')'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment