Created
August 13, 2013 12:20
-
-
Save demiro/6220553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.replaceAll = function(search, replace, ignoreCase) { | |
if (ignoreCase) { | |
var result = []; | |
var _string = this.toLowerCase(); | |
var _search = search.toLowerCase(); | |
var start = 0, match, length = _search.length; | |
while ((match = _string.indexOf(_search, start)) >= 0) { | |
result.push(this.slice(start, match)); | |
start = match + length; | |
} | |
result.push(this.slice(start)); | |
} else { | |
result = this.split(search); | |
} | |
return result.join(replace); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment