Skip to content

Instantly share code, notes, and snippets.

@CodeNegar
Created October 23, 2012 14:29
Show Gist options
  • Save CodeNegar/3939061 to your computer and use it in GitHub Desktop.
Save CodeNegar/3939061 to your computer and use it in GitHub Desktop.
Java: multiple string replace
//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