public static void main(String s[]) throws Exception{
// 混合,包含有数字,字母,特殊符号,空格,汉字
String test3 = "0123456789abcde!@#$%^& 幽雨0123456789abcde!@#$%^& 幽雨";
char[] chars_test3 = test3.toCharArray();
for (int i = 0; i < chars_test3.length; i++) {
String temp = String.valueOf(chars_test3[i]);
if (temp.matches("[^\\x00-\\xff]")) {
// 判断是全角字符
System.out.println("全角 " + temp);
}
else {
// 判断是半角字符
System.out.println("半角 " + temp);
}
}
String num = "12";
System.out.println("长度是:"+num.length());
System.out.println(check_banjiao(num));
}
/**
* @param str
* @return 返回true代表有全角, 返回false代表没有全角。
*/
public static boolean check_banjiao(String str){
char[] chars_test3 = str.toCharArray();
for (int i = 0; i < chars_test3.length; i++) {
String temp = String.valueOf(chars_test3[i]);
if (temp.matches("[^\\x00-\\xff]")) {
// 是全角
return true;
}else {
// 是半角
}
}
return false;
}站长微信:xiaomao0055
站长QQ:14496453