Skip to content

Instantly share code, notes, and snippets.

@fysherman
Created October 27, 2021 02:13
Show Gist options
  • Save fysherman/2bd95db2d536c2bd5c5f3995eeffe501 to your computer and use it in GitHub Desktop.
Save fysherman/2bd95db2d536c2bd5c5f3995eeffe501 to your computer and use it in GitHub Desktop.
Convert Vietnamese string to English
function convertViToEn(str) {
str = str.toLowerCase();
str = str.replace(/à|á|||ã|â||||||ă|||||/g, "a");
str = str.replace(/è|é||||ê||ế|||/g, "e");
str = str.replace(/ì|í|||ĩ/g, "i");
str = str.replace(/ò|ó|||õ|ô||||||ơ|||||/g, "o");
str = str.replace(/ù|ú|||ũ|ư|||||/g, "u");
str = str.replace(/|ý|||/g, "y");
str = str.replace(/đ/g, "d");
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ""); // Huyền sắc hỏi ngã nặng
str = str.replace(/\u02C6|\u0306|\u031B/g, ""); // Â, Ê, Ă, Ơ, Ư
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment