public static boolean isLetter(char c) {
int k = 0x80;
return c / k == 0 ? true : false;
}
public static boolean isNull(String str){
if(str==null||str.trim().equals("")||str.trim().equalsIgnoreCase("null")){
return true;
}else{
return false;
}
}
public static int length(String s) {
if (s == null)
return 0;
char[] c = s.toCharArray();
int len = 0;
for (int i = 0; i < c.length; i++) {
len++;
if (!isLetter(c[i])) {
len++;
}
}
return len;
}
public static double getLength(String s) {
double valueLength = 0;
String chinese = "[\u4e00-\u9fa5]";
for (int i = 0; i < s.length(); i++) {
String temp = s.substring(i, i + 1);
if (temp.matches(chinese)) {
valueLength += 1;
} else {
valueLength += 0.5;
}
}
return Math.ceil(valueLength);
}
轉載來源:http://blog.csdn.net/z69183787/article/details/18843925