Remove accents/diacritics in a string in JavaScript

前端 未结 29 2573
轻奢々
轻奢々 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:51

    This did it for me. JavaScript, Google Apps Scripts, GAS

    function normalizetext(text) {
      var weird = 'öüóőúéáàűíÖÜÓŐÚÉÁÀŰÍçÇ!@£$%^&*()_+?/*."';
    var normalized = 'ouooueaauiOUOOUEAAUIcC                 ';
    var idoff = -1,new_text = '';
    var lentext = text.toString().length -1
    
    for (i = 0; i <= lentext; i++) {
    idoff = weird.search(text.charAt(i));
    if (idoff == -1) {
    new_text = new_text + text.charAt(i);
    } else {
    new_text = new_text + normalized.charAt(idoff);
    }
    
    }
    return new_text;
    
    }
    

提交回复
热议问题