我有这个问题,我正在尝试用àecc替换所有的字符。
我有一个可以工作的原型:
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;
};现在我想将这个原型与我的Clean函数一起使用:
function Clean(temp){
temp.ReplaceAll("è","è");
temp.ReplaceAll("à","à");
temp.ReplaceAll("ì","ì");
temp.ReplaceAll("ò","ò");
temp.ReplaceAll("ù","ù");
temp.ReplaceAll("é","&eacuta;");
return temp;
}现在我想像这样使用我的函数:
var name= document.getElementById("name").value;
var nomePul=Clean(name);为什么这不起作用?怎么啦?
在这种情况下,它可以工作(没有清理我的函数,所以我认为问题出在那里)
var nomePul=nome.ReplaceAll("è","è");有人能帮我吗?
发布于 2012-11-08 03:04:11
使用以下内容:
function Clean(temp){
temp=temp.ReplaceAll("è","è");
temp=temp.ReplaceAll("à","à");
temp=temp.ReplaceAll("ì","ì");
temp=temp.ReplaceAll("ò","ò");
temp=temp.ReplaceAll("ù","ù");
temp=temp.ReplaceAll("é","&eacuta;");
return temp;
}您没有赋值
发布于 2013-05-08 18:32:48
这是replaceAll的另一个实现。希望这能帮助到别人。
String.prototype.replaceAll = function (stringToFind, stringToReplace) {
if (stringToFind === stringToReplace) return this;
var temp = this;
var index = temp.indexOf(stringToFind);
while (index != -1) {
temp = temp.replace(stringToFind, stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
};发布于 2012-11-08 03:05:07
ReplaceAll()返回一个字符串。所以你应该这么做
temp = temp.ReplaceAll("è","è");在Clean()函数中
https://stackoverflow.com/questions/13276374
复制相似问题