Skip to content

Instantly share code, notes, and snippets.

@emanoelqueiroz
Forked from marioplumbarius/remover-acentos.js
Last active August 8, 2017 17:40
Show Gist options
  • Save emanoelqueiroz/9892051db85012319b7965a74494ade3 to your computer and use it in GitHub Desktop.
Save emanoelqueiroz/9892051db85012319b7965a74494ade3 to your computer and use it in GitHub Desktop.
Funcao marota para remover acentos de strings. Foi utilizado expressao regular em cima de caracteres representados na base hexadecimal.
/**
* Remove acentos de caracteres
* @param {String} stringComAcento [string que contem os acentos]
* @return {String} [string sem acentos]
*/
function removerAcentos(str) {
var mapaAcentosHex = {
a : /[\xE0-\xE6]/g,
e : /[\xE8-\xEB]/g,
i : /[\xEC-\xEF]/g,
o : /[\xF2-\xF6]/g,
u : /[\xF9-\xFC]/g,
c : /\xE7/g,
n : /\xF1/g
};
for (var letra in mapaAcentosHex) {
str = str.replace(mapaAcentosHex[letra], letra);
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment