Created
July 7, 2014 19:16
-
-
Save scottmarlow/711023119156fe9e5ead 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
/** | |
* Substitute sub-strings in side of a string. | |
* | |
* @param stringBuilder String buffer to use for substitution (buffer is not reset) | |
* @param from String to substitute from | |
* @param to String to substitute to | |
*/ | |
private static void subst(final StringBuilder stringBuilder, final String from, final String to) { | |
int begin = 0, end = 0; | |
while ((end = stringBuilder.indexOf(from, end)) != -1) { | |
stringBuilder.delete(end, end + from.length()); | |
stringBuilder.insert(end, to); | |
// update positions | |
begin = end + to.length(); | |
end = begin; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment