Created
October 19, 2011 04:02
-
-
Save brennovich/1297452 to your computer and use it in GitHub Desktop.
Replace special characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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