byte转String时怎样把byte中结尾的0取掉???
byte[] test = new byte[36];
test[0] = 'A';
test[1] = 'D';
String teststr = new String(test);
teststr.trim();
int Len = teststr.length();
test[2]到test[35]都是0.
专成teststr 后,变量查看是"AD ".
trim无效
Len还是等于36.
怎样才能把后面的0取掉???
[解决办法]
byte[] test = new byte[36];
test[0] = 'A';
test[1] = 'D';
String teststr = "";
for (byte b: test) {
if (b != 0) {
teststr += (char)b;
}
}
int len = teststr.length();
System.out.println(len);
System.out.println(teststr);