关于java按字节截取带有汉字的字符串的解法if (bytes 1) { for (int i 0 i byteNum i++) { if (bt
关于java按字节截取带有汉字的字符串的解法
if (bytes > 1) {
for (int i = 0; i < byteNum; i++) {
if (bt[i] < 0) {
cutLength++;
}
}
if (cutLength % 2 == 0) {
cutLength /= 2;
}else
{
cutLength=0;
}
}
int result=cutLength+--byteNum;
if(result>bytes)
{
result=bytes;
}
if (bytes == 1) {
if (bt[0] < 0) {
result+=2;
}else
{
result+=1;
}
}
String substrx = new String(bt, 0, result);
System.out.println(substrx);
}
public static void main(String args[]) {
String str = "我abc的DEFe呀fgsdfg大撒旦";
int num =1;
System.out.println("num:" + num);
parseCH sptstr = new parseCH();
sptstr.splitIt(str, num);
}
}
转自:http://lanxia39.iteye.com/blog/190439
