您的位置:首页 > 其它

判断字符串是否仅为数字/首字符是否为字母/汉字

2016-11-03 15:30 513 查看
// 判断字符串是否仅为数字:
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}

// 判断一个字符串的首字符是否为字母
public static boolean test(String s) {
char c = s.charAt(0);
int i = (int) c;
if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122)) {
return true;
} else {
return false;
}
}

// 判断是否为汉字
public static boolean vd(String str) {
char[] chars = str.toCharArray();
boolean isGB2312 = false;
for (int i = 0; i < chars.length; i++) {
byte[] bytes = ("" + chars[i]).getBytes();
if (bytes.length == 2) {
int[] ints = new int[2];
ints[0] = bytes[0] & 0xff;
ints[1] = bytes[1] & 0xff;
if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40
&& ints[1] <= 0xFE) {
isGB2312 = true;
break;
}
}
}
return isGB2312;
}

// 判断是否为汉字
public static boolean isChineseChar(String str) {
boolean temp = false;
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
temp = true;
}
return temp;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐