Return to Snippet

Revision: 14463
at June 4, 2009 16:30 by nalmeida


Initial Code
/**
 * 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);
};

Initial URL

                                

Initial Description

                                

Initial Title
Replace de caracteres especiais por seu equivalente sem acento

Initial Tags
replace

Initial Language
JavaScript