Java把字符串中的数字删除的方法和判断字符串里面是否有汉字的方法

来源:互联网 发布:传奇永恒网络传输异常 编辑:程序博客网 时间:2024/05/20 03:36
1. 把数字删除

 

String testStr = "大幅度要栽夺工地奇巧地厅革dfdsfdsafd32123313";
System.out.println(testStr.replaceAll("[0-9]",""));

 

2.判断是否有汉字

 

public static boolean gbk(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;
 }