I wanted to write a method to avoid special characters, such as "ä", to their Unicode response (e.g. \ u00e4).
For some reason, JS finds it funny not even to save 'ä' internally, but to use 'üÜ' or some other garble, so when I convert it, it rips out '\ u00c3 \ u00b6 \ u00c3 \ u002013' because it converts these instead of "ä".
I tried setting the encoding of the HTML file to utf-8 and tried to load scripts with charset = "UTF-8" to no avail. The code really does nothing special, but here it is:
String.prototype.replaceWithUtf8 = function() { var str_newString = ''; var str_procString = this; for (var i = 0; i < str_procString.length; i++) { if (str_procString.charCodeAt(i) > 126) { var hex_uniCode = '\\u00' + str_procString.charCodeAt(i).toString(16); console.log(hex_uniCode + " (" + str_procString.charAt(i) + ")"); str_newString += hex_uniCode; } else { str_newString += str_procString.charAt(i); } } return str_newString; } var str_item = "Lärm, Lichter, Lücken, Löcher." console.log(str_item);
source share