public class Database { public static void main(String[] args) { String pageContents="fdafdfjfas占应接种人群的31%。15岁以下人群补种乙肝疫苗项目。bfdgfdhf"; Pattern p = Pattern.compile("\u4E00-\u9FA5"); Matcher m = p.matcher(pageContents); while (m.find()) { System.out.println(m.group(1).trim()); } } }这样写对吗,怎么不能输出啊 ?
public void getChinese() { String pageContents="你是fda占应接种人群31%。15岁以下人群。bfdgfdhf世界";
StringBuffer sb = new StringBuffer(); Pattern p = Pattern.compile("[\u4E00-\u9FA5]"); for(int i = 0 ; i<pageContents.length(); i++) { char c = pageContents.charAt(i); String s = c+""; Matcher m = p.matcher(s); if(m.matches()) { sb.append(s); } } System.out.println(sb); }这个方法只能得到汉字,得不到31%, “3”,“1”,“%”都不在\u4E00-\u9FA5 内,估计lz要郁闷。 还有,lz那结贴率……
public static void main(String[] args) {
String pageContents="fdafdfjfas占应接种人群的31%。15岁以下人群补种乙肝疫苗项目。bfdgfdhf";
Pattern p = Pattern.compile("\u4E00-\u9FA5");
Matcher m = p.matcher(pageContents);
while (m.find()) {
System.out.println(m.group(1).trim());
}
} }这样写对吗,怎么不能输出啊 ?
public void getChinese()
{
String pageContents="你是fda占应接种人群31%。15岁以下人群。bfdgfdhf世界";
StringBuffer sb = new StringBuffer();
Pattern p = Pattern.compile("[\u4E00-\u9FA5]");
for(int i = 0 ; i<pageContents.length(); i++)
{
char c = pageContents.charAt(i);
String s = c+"";
Matcher m = p.matcher(s);
if(m.matches())
{
sb.append(s);
}
}
System.out.println(sb);
}这个方法只能得到汉字,得不到31%, “3”,“1”,“%”都不在\u4E00-\u9FA5 内,估计lz要郁闷。
还有,lz那结贴率……