Skip to content

Instantly share code, notes, and snippets.

@shumiyao
Last active March 23, 2023 10:36
Show Gist options
  • Save shumiyao/fe10497d851a36ce04cbc7acd8f7c8fd to your computer and use it in GitHub Desktop.
Save shumiyao/fe10497d851a36ce04cbc7acd8f7c8fd to your computer and use it in GitHub Desktop.
// Convert unicode string to Javascript escape
// https://stackoverflow.com/questions/21014476/javascript-convert-unicode-string-to-javascript-escape
String.prototype.toUnicode = function(){
var result = "";
for(var i = 0; i < this.length; i++){
// Assumption: all characters are < 0xffff
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
}
return result;
};
a = 'Água' // COMBINING ACUTE ACCENT (A%CC%81gua)
b = 'Água' // LATIN CAPITAL LETTER A WITH ACUTE
c = a.normalize()
d = b.normalize()
c == d
// true
a == b
// false
/// references
// (https://design215.com/toolbox/ascii-utf8.php)[Design215.com - South Florida Photography, Design, and Web ServicesABOUTSERVICESWORKTOOLBOXCONTACT
UTF-8 AND ASCII CHARACTER CHART]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment