byte转String时怎样把byte中结尾的0取掉
1个回答
展开全部
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);
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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询