1.当需要截取传入的文本前多少个字节显示时:可以使用此方法:正则表达式
if(content.length()>30){
content = content.substring(0,30);
int valueLength = 0;
int total=0;
String chinese = "[\u4e00-\u9fa5]";
for (int lxj = 0; lxj < content.length(); lxj++) {
String temp = content.substring(lxj, lxj + 1);
if (temp.matches(chinese)) {
valueLength += 2;
} else {
valueLength += 1;
}
if(valueLength==29||valueLength==30){
total = lxj;
break;
}
}
content = content.substring(0,total);
}
2.