1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| @Test public void test4(){ String str1 = "北京尚硅谷教育北京"; String str2 = str1.replace('北', '东');
System.out.println(str1); System.out.println(str2);
String str3 = str1.replace("北京", "上海"); System.out.println(str3);
System.out.println("*************************"); String str = "12hello34world5java7891mysql456"; String string = str.replaceAll("\\d+", ",").replaceAll("^,|,$", ""); System.out.println(string);
System.out.println("*************************"); str = "12345"; boolean matches = str.matches("\\d+"); System.out.println(matches); String tel = "0571-4534289"; boolean result = tel.matches("0571-\\d{7,8}"); System.out.println(result);
System.out.println("*************************"); str = "hello|world|java"; String[] strs = str.split("\\|"); for (int i = 0; i < strs.length; i++) { System.out.println(strs[i]); } System.out.println(); str2 = "hello.world.java"; String[] strs2 = str2.split("\\."); for (int i = 0; i < strs2.length; i++) { System.out.println(strs2[i]); }
}
|