Remove accents/diacritics in a string in JavaScript

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

    $scope.legal_name = $sanitize($scope.legal_name);
        console.log("Name before function...",$scope.legal_name);
    
        var str = "";
        for(var i=0; i < $scope.legal_name.length; i++) {
            var charName = $scope.legal_name.charAt(i);
            if((charName == '&') && ($scope.legal_name.charAt(i + 1) == '#')){
                var count = 0;
                var subString = "";
                while(true) {
                    if(($scope.legal_name.charCodeAt(i + 2 + count) > 47) && ($scope.legal_name.charCodeAt(i + 1 + count) < 58 )) {
                        subString = subString + $scope.legal_name.charAt(i + 2 + count);
                        count++;
                    } else {
                        if(subString.length > 0) {
                            var value = parseInt(subString);
                            str = str + String.fromCharCode(value);
                            i = i + 1 + count; 
                            break;
                        }
                    }
                }               
            } else {
                str = str + charName;
            }
        }
        $scope.legal_name = str;
        console.log("Name After function...",str);
    

提交回复
热议问题