讨论:java 如何有效实现对一段英文文章的,单词,行数的统计。 如题,我想用空格实现,单词计数。但是对标点符号不能很好的处理。希望有兴趣的朋友参与。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用正则String str="";//文章int words=0;int punc=0;Pattern p=Pattern.compile("(\\w+)");//找单词Matcher m=p.matcher(str);while(m.find())words++;p = Pattern.compile("[,\\.;:'\",。、?;:’”]");m = p.matcher(str);while(m.find())punc++; 静态变量实例化问题呀 定时运行的jar文件的windows应用程序如何写 多文件上传时能不能不关闭客户端socket eclipse问题? Exception异常的疑问 [求助]javax.swing.JTextField控件的右键菜单问题 如果父类和接口都定义了一个abstract public方法 那么儿类究竟实现的谁的? 关于一个图形输出的问题??救我 请教:JAXP中的Attributes到底是什么 JB6的序列号? 怎样清空JLIST中的数据? JDK5.0兼容以前的版本吗 兼容性怎样?
String str="";//文章
int words=0;
int punc=0;
Pattern p=Pattern.compile("(\\w+)");//找单词
Matcher m=p.matcher(str);
while(m.find())
words++;
p = Pattern.compile("[,\\.;:'\",。、?;:’”]");
m = p.matcher(str);
while(m.find())
punc++;