62,628
社区成员
发帖
与我相关
我的任务
分享 // 计算byte[]的实际大小
int getByteLength(byte[] res) {
int len = 0;
for (int pos = 0; pos < res.length; pos++) {
if (res[pos] != 0) {
len++;
} else {
break;
}
}
return len;
}
String retStr = new String(b);
String str1=retStr.trim();//直接去掉它后面的空格
System.out.println(str1.length());
String str= new String(b);
str.substring(str.indexOf(' ')); public static String trim(String str) {
byte[] bs = str.getBytes();
int p = 0;
for (int i = 0; i < bs.length; i++) {
if (bs[i] == 0) {
p = i;
break;
}
}
byte[] b = new byte[p];
System.arraycopy(bs, 0, b, 0, b.length);
return new String(b);
}
String str = "字符串测试";
byte[] b = new byte[str.getBytes().length];
System.arraycopy(str.getBytes(), 0, b, 0, str.getBytes().length);
String temp = new String(b);
System.out.println(temp + ":");