Javascript removing accents

后端 未结 1 638
我寻月下人不归
我寻月下人不归 2021-01-17 05:44

I want to use Evan Elliott\'s code (below) to remove accents in strings but its returns an \"a\" instead of the respective vanilla version of each character. I declare

1条回答
  •  再見小時候
    2021-01-17 06:08

    This function may be useful for what you need:

    function removeAccents (text) {
        var accents    = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž',
            accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz",
            textNoAccents = [];
    
        for (var i in text) { 
            var idx = accents.indexOf(text[i]);
            if (idx != -1)
                textNoAccents[i] = accentsOut.substr(idx, 1);
            else
                textNoAccents[i] = text[i];
        }
    
        return textNoAccents.join('');
    }
    

    0 讨论(0)
提交回复
热议问题