unique
2015-07-29 17:48:40 +08:00
final String str = "asdasd as8 923 (*&)^%$";
Pattern pattern = Pattern.compile("[a-zA-Z]+");
Matcher m = pattern.matcher(str);
int yw = 0,sz = 0, kg = 0, other = 0;
while (m.find()) {
yw += m.group().length();
}
System.out.println("英文:" + yw);
pattern = Pattern.compile("[\\d]+");
m = pattern.matcher(str);
while (m.find()) {
sz += m.group().length();
}
System.out.println("数字:" + sz);
pattern = Pattern.compile("[\\s]+");
m = pattern.matcher(str);
while (m.find()) {
kg += m.group().length();
}
System.out.println("空格:" + kg);
pattern = Pattern.compile("[^a-zA-Z0-9\\s]+");
m = pattern.matcher(str);
while (m.find()) {
other += m.group().length();
}
System.out.println("其他字符:" + other);
楼主是这个意思?