package net.okren.java;
import java.util.*;
//将逗号分隔的字符串 转换成 Byte数组,
class GetByte{
public byte[] getByte(String str){
System.out.println("getByte...");
int wn = 0;
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == ','){wn++;}
}
wn++;
byte[] reByte = new byte[wn];
for(int i = 0; i < wn; i++){
if( i != (wn - 1)){
reByte[i] = (byte) Integer.valueOf(str.substring(0, str.indexOf(",")), 16).intValue();
str = str.substring(str.indexOf(",") + 1, str.length());
}else{
reByte[i] = (byte) Integer.valueOf(str, 16).intValue();
}
}
return reByte;
}
}
public class JavaTest {
public static void main(String[] args) throws NumberFormatException{
GetByte gb = new GetByte();
System.out.println("input a string ,,,");
Scanner in = new Scanner(System.in);
String line = in.nextLine();
System.out.println(line);
byte[] bb = gb.getByte(line);
for(int i = 0; i < bb.length; i++){
System.out.println(bb[i]);
}
}
}
将逗号分隔的字符串 转换成 Byte数组,
最新推荐文章于 2023-07-04 09:03:18 发布