Remove accents/diacritics in a string in JavaScript

前端 未结 29 2572
轻奢々
轻奢々 2020-11-21 13:29

How do I remove accentuated characters from a string? Especially in IE6, I had something like this:

accentsTidy = function(s){
    var r=s.toLowerCase();
           


        
29条回答
  •  無奈伤痛
    2020-11-21 13:42

    I found all these a little clumsy and I'm not too expert on regular expressions, so here's a simpler version. It would be quite easy to translate it to your favourite server-side language, assuming that the string already in Unicode:

    // String containing replacement characters for stripping accents 
    var stripstring = 
        'AAAAAAACEEEEIIII'+
        'DNOOOOO.OUUUUY..'+
        'aaaaaaaceeeeiiii'+
        'dnooooo.ouuuuy.y'+
        'AaAaAaCcCcCcCcDd'+
        'DdEeEeEeEeEeGgGg'+
        'GgGgHhHhIiIiIiIi'+
        'IiIiJjKkkLlLlLlL'+
        'lJlNnNnNnnNnOoOo'+
        'OoOoRrRrRrSsSsSs'+
        'SsTtTtTtUuUuUuUu'+
        'UuUuWwYyYZzZzZz.';
    
    function stripaccents(str){
        var answer='';
        for(var i=0;i=0 && chindex

提交回复
热议问题