62,621
社区成员
发帖
与我相关
我的任务
分享
String s = "123Hi, 1how are you? 3I'm fine, thank you.";
s = s.replaceAll("\\d+", "");
String[] ss = s.split("(\\s+|-|'|,|\\.|\\?)");
for (String str : ss) {
System.out.println(str);
}
楼主的要求没说清楚,如果是I'm这种缩写的情况怎么处理
有些特殊符号应该不用统计在内的~上面代码稍微改了改,借花献佛了. public static void main(String[] args) {
String s = "123Hi, 1how are you? 3I'm fine, thank you.";
s = s.replaceAll("\\d+", "");
String[] ss = s.split("(\\s+|-|')");
System.out.println(ss.length);
for(String str : ss){
System.out.println(str);
}
}