Skip to content

Instantly share code, notes, and snippets.

@brennovich
Created October 19, 2011 04:02
Show Gist options
  • Save brennovich/1297452 to your computer and use it in GitHub Desktop.
Save brennovich/1297452 to your computer and use it in GitHub Desktop.
Replace special characters
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:"?!()"}
];
function replaceSpecialChars(string) {
var $spaceSymbol = '-';
var regex;
var result = string;
for (var i = 0; i < specialChars.length; i++) {
regex = new RegExp("["+specialChars[i].let+"]", "g");
result = returnString.replace(regex, specialChars[i].val);
regex = null;
}
return result.replace(/\s/g,$spaceSymbol);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment