区别中文和英文字符的方法:
String str = "我爱你,xr"; char[] array = str.toCharArray(); int chineseCount = 0; int englishCount = 0; for (int i = 0; i < array.length; i++) { if((char)(byte)array[i]!=array[i]){ chineseCount++; }else{ englishCount++; } }
判断是否包含特殊字符的方法:
Pattern p = Pattern.compile("[&%$#@!(),*^]"); //可在此加上其他的特殊字符 Matcher m = p.matcher(str); if (m.find()) { Toast.makeText(getApplicationContext(),"you can not enter special Character", 1).show(); } else { Toast.makeText(getApplicationContext(),"input ok", 1).show(); }
作者:chenshijun0101 发表于2013-4-1 16:09:40 原文链接
阅读:0 评论:0 查看评论