定长字节报文,字节截取

指定字节长度的字符串,临时写了个截取...
 
 
int[] lengthList = {8,32,16,2,14,14,32,120,120,8,100,120,1,120};
	   	int start = 0;
	   	int end = lengthList[0];
	   	byte[] valueByte = value.getBytes("GBK");
	   	for (int i = 0; i < lengthList.length; i++) {
	   		//按字节截取
    		valueSub += "'"+new String(valueByte, start, end-start)+"',";
    		//按字符串截取
    		//valueSub += "'"+value.substring(start, end).trim()+"',";
			start = lengthList[i] + start;
			if (lengthList.length-1 != i) {
				end = start + lengthList[i+1];
			}
		}

你可能感兴趣的:(截取,定长报文)