Replace Accent Char

Hi experts,

I need to replace all the accent from a string:

é->e è->e à->a

I need a very compact script.

cabouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
Like this:

var newStr = oldStr.replace(/[éè]/g,"e").replace(/[à]/g,"a");

0
KennyTMCommented:
function replace_accent_chars (str) {
    function rac_analyzer (x) {
            if (x < 'ß')
                  return rac_analyzer(x.toLowerCase()).toUpperCase();
            else {
                  switch (x) {
                        case 'à': case 'á': case 'â': case 'ã': case 'ä': case 'å':
                              return 'a';
                        case 'æ':
                              return 'ae';
                        case 'ç':
                              return 'c';
                        case 'è': case 'é': case 'ê': case 'ë':
                              return 'e';
                        case 'ì': case 'í': case 'î': case 'ï':
                              return 'i';
                        case 'ð':
                              return 'd';
                        case 'ñ':
                              return 'n';
                        case 'ò': case 'ó': case 'ô': case 'õ': case 'ö': case 'ø':
                              return 'o';
                        case 'ù': case 'ú': case 'û': case 'ü':
                              return 'u';
                        case 'ý': case 'ÿ':
                              return 'y';
                        case 'þ':
                              return 'th';
                        case 'ß':
                              return 'ss';
                        default:
                              alert('à'.charCodeAt(0));
                              return x;
                  }
            }
    }
   
    return str.replace(/[À-ÿ]/g, rac_analyzer);
}

alert (replace_accent_chars ("Ampère's law and l'Hôpital's rule") );
0
KennyTMCommented:
// Replacing all accented characters in ISO-8859-1 range.

function replace_accent_chars (str) {
    function rac_analyzer (x) {
            if (x < 'ß')
                  return rac_analyzer(x.toLowerCase()).toUpperCase();
            else {
                  switch (x) {
                        case 'à': case 'á': case 'â': case 'ã': case 'ä': case 'å':
                              return 'a';
                        case 'æ':
                              return 'ae';
                        case 'ç':
                              return 'c';
                        case 'è': case 'é': case 'ê': case 'ë':
                              return 'e';
                        case 'ì': case 'í': case 'î': case 'ï':
                              return 'i';
                        case 'ð':
                              return 'd';
                        case 'ñ':
                              return 'n';
                        case 'ò': case 'ó': case 'ô': case 'õ': case 'ö': case 'ø':
                              return 'o';
                        case 'ù': case 'ú': case 'û': case 'ü':
                              return 'u';
                        case 'ý': case 'ÿ':
                              return 'y';
                        case 'þ':
                              return 'th';
                        case 'ß':
                              return 'ss';
                        default:
                              return x;
                  }
            }
    }
   
    return str.replace(/[À-ÿ]/g, rac_analyzer);
}

alert (replace_accent_chars ("Ampère's law and l'Hôpital's rule") );
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cabouAuthor Commented:
Kenny,

I like your code but when I runs it into my page the Special Char desepears...
What do I have to do?

You can see it at:
http://beta.a7fr.com
0
dbrittCommented:
You need to save it in a different encoding.
0
KennyTMCommented:
I cannot see any "Special Chars" (those <?>'s ?), but, as dbritt has said, this may be an encoding problem.

Make sure the page is in UTF-8...
Try adding this into the <head> section:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.