Guest User

Untitled

a guest
Jan 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. //string:字符串表达式包含要替代的子字符串。
  2. //reallyDo:被搜索的子字符串。
  3. //replaceWith:用于替换的子字符串。
  4.  
  5. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  6. if(!RegExp.prototype.isPrototypeOf(reallyDo)) {
  7. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
  8. } else {
  9. return this.replace(reallyDo, replaceWith);
  10. }
  11. }
  12.  
  13. var string = 'abcdefabcdefabcdef';
  14. console.log(string.replaceAll('b',"0",false));//结果:a0cdefa0cdefa0cdef
Add Comment
Please, Sign In to add comment