Created
August 23, 2018 19:31
-
-
Save lokeb/f4818fb57380566d57991374459805c7 to your computer and use it in GitHub Desktop.
Prototype methods to convert Currency.csv Unicode values
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
String.prototype.hexDecode = function () { | |
var j; | |
var hexes = this.split("\\u").slice(1); | |
var back = ""; | |
for (j = 0; j < hexes.length; j++) { | |
back += String.fromCharCode(parseInt(hexes[j], 16)); | |
} | |
return back; | |
} | |
String.prototype.hexEncode = function () { | |
var hex, i; | |
var result = ""; | |
for (i = 0; i < this.length; i++) { | |
hex = this.charCodeAt(i).toString(16); | |
result += "\\u" + ("000" + hex).slice(-4); | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex