public static int strlen(String str) {
if (str == null || str.length() <= 0) {
return 0;
}
int len = 0;
char c;
for (int i = str.length() - 1; i >= 0; i--) {
c = str.charAt(i);
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')) {
// 字母, 数字
len++;
} else {
if (Character.isLetter(c)) { // 中文
len += 2;
} else { // 符号或控制字符
len++;
}
}
}
return len;
}