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

来源:互联网 发布:手机数据流量改dns 编辑:程序博客网 时间:2024/06/12 05:58
// 判断字符串是否仅为数字:    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;    }
0 0
原创粉丝点击