# Posted By

nalmeida on 06/04/09

# Statistics

Viewed 470 times
Favorited by 0 user(s)

# Replace de caracteres especiais por seu equivalente sem acento

/ Published in: JavaScript
`/** * Array de objectos de qual caracter deve substituir seu par com acentos */var specialChars = [	{val:"a",let:"Ã¡Ã Ã£Ã¢Ã¤"},	{val:"e",let:"Ã©Ã¨ÃªÃ«"},	{val:"i",let:"Ã­Ã¬Ã®Ã¯"},	{val:"o",let:"Ã³Ã²ÃµÃ´Ã¶"},	{val:"u",let:"ÃºÃ¹Ã»Ã¼"},	{val:"c",let:"Ã§"},	{val:"A",let:"ÃÃ€ÃƒÃ‚Ã„"},	{val:"E",let:"Ã‰ÃˆÃŠÃ‹"},	{val:"I",let:"ÃÃŒÃŽÃ"},	{val:"O",let:"Ã“Ã’Ã•Ã”Ã–"},	{val:"U",let:"ÃšÃ™Ã›Ãœ"},	{val:"C",let:"Ã‡"},	{val:"",let:"?!()"}]; /** * FunÃ§Ã£o para substituir caractesres especiais. * @param {str} string * @return String */function replaceSpecialChars(str) {	var \$spaceSymbol = '-';	var regex;	var returnString = str;	for (var i = 0; i < specialChars.length; i++) {		regex = new RegExp("["+specialChars[i].let+"]", "g");		returnString = returnString.replace(regex, specialChars[i].val);		regex = null;	}	return returnString.replace(/\s/g,\$spaceSymbol);};`