Created
October 23, 2012 14:29
-
-
Save CodeNegar/3939061 to your computer and use it in GitHub Desktop.
Java: multiple string replace
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
//array to hold replacements | |
String[][] replacements = {{"call me", "cm"}, | |
{"as soon as possible", "asap"}}; | |
//loop over the array and replace | |
String strOutput = inString; | |
for(String[] replacement: replacements) { | |
strOutput = strOutput.replace(replacement[0], replacement[1]); | |
} | |
System.out.println(strOutput); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment