旦public void splitIt(String splitStr, int bytes) {
int cutLength = 0;
int byteNum = bytes;
byte bt[] = splitStr.getBytes();
for (byte b : bt) {
System.out.println(b+" **");
}
System.out.println("Length of this String ===>" + bt.length);
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 = "我的的的a旦bc的DEFe呀fgsdfg大撒旦";
int num = 3;
System.out.println("num:" + num);
test sptstr = new test();
sptstr.splitIt(str, num);
}