Skip to content

Instantly share code, notes, and snippets.

@antpaw
Created April 12, 2011 20:20
Show Gist options
  • Save antpaw/916306 to your computer and use it in GitHub Desktop.
Save antpaw/916306 to your computer and use it in GitHub Desktop.
useful for String.fromCharCode();
String.prototype.toCharCode = function(){
var str = this.split('');
var work = [];
for (var i = 0; i < str.length; ++i){
work.push(str[i].charCodeAt(0));
}
return work;
};
console.log('test'.toCharCode().join(','));
@JavaScript-Packer
Copy link

var toCharCode = function(x) {
  var o, e = x.split(""), t = [];
  for (o in e) t.push(e[o].charCodeAt(0));
  return t;
};

var unCharCode = function(x) {
  return this["eval"]("String.fromCharCode(" + x + ")");
};

console.log(toCharCode("test").join(","));

console.log(unCharCode("119,119,119,46,87,72,65,75,46,99,111,109"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment