功能,将文字按标点分段,标点归于上一段文字String in = "abc;tdhwd.ee!ff,er?ec:k$k";
Pattern ptn = Pattern.compile("([^,.?;:!]+[,.?;:!])|([^,.?;:!]+$)");
Matcher mc = ptn.matcher(in);
Vector ct = new Vector();
while (mc.find()) {
ct.addElement(mc.group(0));
}
Enumeration e = ct.elements();
while (e.hasMoreElements()) System.out.println(e.nextElement());
Pattern ptn = Pattern.compile("([^,.?;:!]+[,.?;:!])|([^,.?;:!]+$)");
Matcher mc = ptn.matcher(in);
Vector ct = new Vector();
while (mc.find()) {
ct.addElement(mc.group(0));
}
Enumeration e = ct.elements();
while (e.hasMoreElements()) System.out.println(e.nextElement());
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货