Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //string:字符串表达式包含要替代的子字符串。
- //reallyDo:被搜索的子字符串。
- //replaceWith:用于替换的子字符串。
- 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);
- }
- }
- var string = 'abcdefabcdefabcdef';
- console.log(string.replaceAll('b',"0",false));//结果:a0cdefa0cdefa0cdef
Add Comment
Please, Sign In to add comment