/**
* 中文字符串截取
* @param origin 要截取的字符串
* @param length 截取的字节数.
*/
public String substring(String origin, int length) {
String[] aryStr = origin.split("");
StringBuffer str = new StringBuffer("");
int cntNum = 0; // 当前字节数.
int cc = 0; // 当前汉字数.
for (int i = 0; i < aryStr.length; i++) {
if (aryStr[i].getBytes().length == 1) {
cntNum++;
str.append(aryStr[i]);
} else if (aryStr[i].getBytes().length == 2) {
cc++;
cntNum += 2;
str.append(aryStr[i]);
}
if (cntNum >= length) break;
}
if (cntNum > length) {
return str.substring(0, length - cc);
} else {
return str.toString();
}
}