Created
February 22, 2016 10:34
-
-
Save naugtur/1d2227b09601e50dc9e0 to your computer and use it in GitHub Desktop.
string multireplace not regexp
This file contains hidden or 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
| function replaceSubstring(inSource, inToReplace, inReplaceWith) { | |
| var outString = []; | |
| var repLen = inToReplace.length; | |
| var idx = inSource.indexOf(inToReplace); | |
| while (idx !== -1) { | |
| outString.push(inSource.substring(0, idx)) | |
| outString.push(inReplaceWith); | |
| inSource = inSource.substring(idx + repLen); | |
| idx = inSource.indexOf(inToReplace); | |
| } | |
| outString.push(inSource); | |
| return outString.join(""); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment