I want to convert mixed string like this "Dаtе" where "a" is in utf16 (1072 decimal) into utf8 (97 decimal):
const mixedString = "Dаtе";
const expectedString = "Date";
const toCharCodes = (str) => {
return Array.from(Array(str.length).keys()).map(i => str.charCodeAt(i));
}
console.log(toCharCodes(mixedString)); // [68,1072,116,1077]
console.log(toCharCodes(expectedString)); // [68,97,116,101]
console.log(mixedString === expectedString) // false;
How to convert utf8/utf16 strings to utf8?