Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. someString = 'the cat looks like a cat'
  2. anotherString = someString.replace('cat', 'dog');
  3.  
  4. someString = 'the cat looks like a cat';
  5. anotherString = someString.replace(/cat/g, 'dog');
  6. // anotherString now contains "the dog looks like a dog"
  7.  
  8. anotherString = someString.replace(/cat/g, 'dog');
  9.  
  10. function multiReplace(str, match, repl) {
  11. do {
  12. str = str.replace(match, repl);
  13. } while(str.indexOf(match) !== -1);
  14. return str;
  15. }
  16.  
  17. multiReplace("the cat looks like a cat", "cat", "dog"); // "the dog looks like a dog"
Add Comment
Please, Sign In to add comment