import java.util.regex.*; public class TestToDel { public static void main(String[] args) { String s = " abc d 滚 "; Pattern pa = Pattern.compile("[\u4E00-\u9FA0]",Pattern.CANON_EQ); Matcher m = pa.matcher(s); while(m.find()){ System.out.println(m.group()); } } } 这样就可以把汉字筛选出来 !
if (inStr.getBytes().length != inStr.length()) {
return true;
}
return false;
}
判断是否含有汉字如果你只能出入数字和字母,那分别写两个方法判断是否字母是否数字就可以了
--------------------------
判断字符串中是否含有字母及数字外的东东
public static boolean haveOther(String s)
{
int len = s.length();
for (int i=0; i<len; ++i)
{
char ch = s.charAt(i);
if (!(((ch > 'a') && (ch < 'z')) || ((ch>'A') && (ch < 'Z')) || ((ch > '0') && (ch < '9'))))
{
return true;
}
}
return false;
}
public class TestToDel {
public static void main(String[] args) {
String s = " abc d 滚 ";
Pattern pa = Pattern.compile("[\u4E00-\u9FA0]",Pattern.CANON_EQ);
Matcher m = pa.matcher(s);
while(m.find()){
System.out.println(m.group());
}
}
}
这样就可以把汉字筛选出来 !