I have this problem I'm triyng to replace all the charachters like àòùèì with à ecc...
I have this prototype that works:
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
var temp = this;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
};
Now I want to use this prototype with my function called Clean:
function Clean(temp){
temp.ReplaceAll("è","è");
temp.ReplaceAll("à","à");
temp.ReplaceAll("ì","ì");
temp.ReplaceAll("ò","ò");
temp.ReplaceAll("ù","ù");
temp.ReplaceAll("é","&eacuta;");
return temp;
}
and now I want to use my function like this:
var name= document.getElementById("name").value;
var nomePul=Clean(name);
Why this does not work? What is wrong?
In this case it works (without my function clean, so I think the problem is there)
var nomePul=nome.ReplaceAll("è","è");
Someone can help me?
temp.ReplaceAll("è", "è");, the typical way to replace all instances of a string in Javascript is to use a regex:temp.replace(/è/g, "è");.