我有一个可以从字符串中删除单词的函数。它是:
var removeFromString = function(oldStr, fullStr) {
return fullStr.split(oldStr).join('');
};
我这样使用它:
console.log( removeFromString("Hello", "Hello World") ); // World
console.log( removeFromString("Hello", "Hello-World") ); // -World
但主要问题是:
var str = "Remove one, two, not three and four";
在这里,我们需要移除 "one"、"two" 和 "four"。可以通过以下方式完成:
var a = removeFromString("one, two,", str); // Remove not three and four
var b = removeFromString("and four", a); // Remove not three
console.log(b); // Remove not three
在上面的例子中,我不得不两次使用该函数。我希望它像这样:
var c = removeFromString(["one, two," , "and four"], str); // Remove not three
console.log(c); // Remove not three
是的,我确实想升级removeFromString函数!我该怎么做?