81,092
社区成员
发帖
与我相关
我的任务
分享
public class Cut {
public String cut(String s, int n) {
String c="";
String d = "";
String[] b = s.split("");
for (int i = 0; i < b.length; i++) {
c = c + b[i];
if((c.getBytes().length)==n){
d = d + b[i];
break;
}else if((c.getBytes().length)>n){
break;
}
d = d + b[i];
}
return d;
}
public static void main(String[] args) {
Cut cu = new Cut();
String a = cu.cut("a接口cd喊f", 4);
System.out.println(a);
}
}
public static void getChar(String str, int count) {
byte[] byteArray = new byte[count];
byte[] temp = str.getBytes();
int ii = 0;
for (int i = 0; i < count; i++) {
byteArray[i] = temp[i];
if (temp[i] < 0) {
ii++;
}
}
if (ii % 2 == 1) {
byteArray[count - 1] = ' ';
}
System.out.println(new String(byteArray).trim());
}