Created
September 10, 2015 15:52
-
-
Save AnEmortalKid/015e86ea4a49a30dcc79 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
public class StringReplaceStuff { | |
public static void main(String[] args) { | |
String testString = "Hello World!"; | |
// replace o with 0, replaceAll takes a string pattern to replace | |
String osReplaced = testString.replaceAll("o", "0"); | |
System.out.println("Without O = " + osReplaced); | |
// if we want to add to our replacement, we need to do it in different | |
// step strings | |
String esReplaced = osReplaced.replaceAll("e", "3"); | |
System.out.println("Without O and E= " + esReplaced); | |
// otherwise if we just want to print different transformations | |
System.out.println(testString.replaceAll("o", "0")); | |
System.out.println(testString.replaceAll("e", "3")); | |
/* | |
* Note: replaceAll returns a MODIFIED string, Strings are immutable so | |
* you need to keep assigning the result of replaceAll in order to | |
* achieve your transformation | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment