我想通过将字符串中的每个字符与数组中的字符进行比较并用匹配的字符替换它来消除字符串中的特殊字符。下面的函数不会抛出任何错误,但会保持原样返回字符串
var name = "przykład";
// the characters i'm looking for in a string:
var charList = ["Ą","ą","Ć","ć","Ę","ę","Ł","ł","Ó","ó","Ś","ś","Ź","ź","Ż","ź"];
// the characters i'd like to replace them with:
var replaceList = ["A","a","C","c","E","e","L","l","O","o","S","s","Z","z","Z","z"];
var limit = name.length;
for (i = 0; i < limit; i++){
for(var j in charList){
name.charAt(i) === charList[j] ? name.replace(name.charAt(i), replaceList[j]) : "";
}
}
return name;
我知道这个问题很可能会因为“过于本地化”而被关闭,这可能是我犯的一个愚蠢而简单的错误,但我仍然非常感谢任何帮助