|
| 1 | +package eu.happycoders.string.basics.en; |
| 2 | + |
| 3 | +import java.util.Locale; |
| 4 | + |
| 5 | +public class Ch6Changing { |
| 6 | + |
| 7 | + static void main() { |
| 8 | + System.out.println("1.2.3".replace('.', '_')); |
| 9 | + System.out.println("1.2.3".replace(".", "")); |
| 10 | + System.out.println("1.2.3".replaceAll(".", "")); |
| 11 | + System.out.println("1.2.3".replaceAll("\\.", "")); |
| 12 | + |
| 13 | + System.out.println("a1b22c333".replaceAll("\\d+", "#")); |
| 14 | + System.out.println("a1b22c333".replaceFirst("\\d+", "#")); |
| 15 | + |
| 16 | + System.out.println("Hello".replace("l", "")); |
| 17 | + |
| 18 | + System.out.println("== Upper and lower case"); |
| 19 | + System.out.println("Straße".toUpperCase(Locale.ROOT)); |
| 20 | + Locale turkish = Locale.forLanguageTag("tr"); |
| 21 | + System.out.println("title".toUpperCase(turkish)); |
| 22 | + System.out.println("TITLE".toLowerCase(turkish)); |
| 23 | + System.out.println("title".toUpperCase(Locale.ROOT)); |
| 24 | + |
| 25 | + System.out.println("== repeat() and reverse"); |
| 26 | + System.out.println("-".repeat(10)); |
| 27 | + System.out.println(new StringBuilder("Hello").reverse().toString()); |
| 28 | + |
| 29 | + System.out.println("== stripIndent() and indent()"); |
| 30 | + String sql = " SELECT name\n FROM users"; |
| 31 | + System.out.println(sql); |
| 32 | + System.out.println(sql.stripIndent()); |
| 33 | + System.out.print(sql.stripIndent().indent(2)); |
| 34 | + |
| 35 | + System.out.println("== translateEscapes()"); |
| 36 | + String raw = "Name:\\tAda\\nName:\\tGrace"; |
| 37 | + System.out.println(raw); |
| 38 | + System.out.println(raw.translateEscapes()); |
| 39 | + } |
| 40 | +} |
0 commit comments