Here you can find the source of hexDecode()
String.prototype.hexDecode = function() { var j;/*ww w . j a v a2 s .co m*/ var hexes = this.match(/.{1,4}/g) || []; var back = ""; for (j = 0; j < hexes.length; j++) { back += String.fromCharCode(parseInt(hexes[j], 16)); } return back; }; function unicode2chinese(str) { return unescape(str.replace(/\\u/g, '%u')); } var str = "\u6f22\u5b57"; // "\u6f22\u5b57" === "??" console.log(str.hexEncode().hexDecode()); console.log(unicode2chinese(str));
String.prototype.hexDecode8 = function(){ var j; var hexes = this.match(/.{1,2}/g) || []; var back = ""; for(j = 0; j<hexes.length; j++) { back += String.fromCharCode(parseInt(hexes[j], 16)); return back;