String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if(!RegExp.prototype.isPrototypeOf(reallyDo)) { return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith); } else { return this.replace(reallyDo, replaceWith); } }
- string:字符串表达式包含要替代的子字符串。
- reallyDo:被搜索的子字符串。
- replaceWith:用于替换的子字符串。
用法
var string = 'abcdefabcdefabcdef'; console.log(string.replaceAll('b',"0",false));//结果:a0cdefa0cdefa0cdef
参考
http://fuleonardo.iteye.com/blog/
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/213911.html原文链接:https://javaforall.net
