java 分解字符串

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:01:07
This is good book! If you read it everyday, you will find it very instructive.
用"!,."分解

String str = "This is good book! If you read it everyday, you will find it very instructive.";
String a[] = str.split(",");
for(int i=0; i<a.length; i++) {
String b[] = a[i].split("!");
for(int n=0; n<b.length; n++) {
System.out.println(b[n]);
}
}
笨办法 呵呵

String str = "This is good book! If you read it everyday, you will find it very instructive.";
String a[] = str.split("[!,.]");
for (int n = 0; n < a.length; n++) {
System.out.println(a[n]);
}

呵呵,正则表达式。。