/*
* 切割功能:
* public String[] split(String regex)
*/
public class RegexDemo {
public static void main(String[] args) {
// 切割字符串"aa,bb,cc";
String str = "aa,bb,cc";
String regex = ",";
String[] strArray = str.split(regex);
for (String s : strArray) {
System.out.println(s);
}
System.out.println("**************");
// 切割字符串"aa.bb.cc"
String str2 = "aa.bb.cc";
String regex2 = "\\.";
String[] strArray2 = str2.split(regex2);
for (String s : strArray2) {
System.out.println(s);
}
System.out.println("**************");
// 切割字符串"-1 99 4 23"
String str3 = "-1 99 4 23";
String regex3 = " ";
String[] strArray3 = str3.split(regex3);
for (String s : strArray3) {
System.out.println(s);
}
System.out.println("**************");
// 切割字符串"-1 99 4 23"
String str4 = "-1 99 4 23";
String regex4 = " +";
String[] strArray4 = str4.split(regex4);
for (String s : strArray4) {
System.out.println(s);
}
System.out.println("**************");
// 切割字符串"D:\itcast\20131130\day27\code"
String str5 = "D:\\itcast\\20131130\\day27\\code";
String regex5 = "\\\\";
String[] strArray5 = str5.split(regex5);
for (String s : strArray5) {
System.out.println(s);
}
}
}
|
|