/**
* 截取字符
*
* @param str
* @param bytes
* @return
*/
public static String SplitString(String str, int bytes) {
//统计字节数
int count = 0;
//返回字符串
StringBuffer reStr = new StringBuffer();
if (str == null) {
return "";
}
char[] tempChar = str.toCharArray();
for (int i = 0; i < tempChar.length; i++) {
if(!(tempChar[i]>255)) {
count = count + 1;
} else {
count = count + 2;
}
if (count <= bytes) {
reStr.append(tempChar[i]);
}
}
return reStr.toString();
}
截取字符串
最新推荐文章于 2024-10-18 17:20:06 发布