/**
* 此方法描述的是:取指定长度字符串的值;
* @param String str,int byteSize;
* @return String;
*/
public String getAllStringSize(String str, int byteSize) {
int len = 0;
char c;
String words = "";
if(str == null || "null".equals(str)) {
return "";
}
for(int i = 0; i < str.length(); i++) {
c = str.charAt(i);
if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
// 字母, 数字
len++;
}else {
if(String.valueOf(c).matches("[\\u4e00-\\u9fa5]")) { // 中文
len += 2;
}else { // 符号或控制字符
len++;
}
}
words += String.valueOf(c);
if(len >= byteSize) {//
words += "..";
break;
}
}
return words;
}