/** * 去除控制字符,保证数据正确 * */ private String changeCtlChar(String vehicleNo){ String value = ""; if(vehicleNo == null){ return value; } String[] chars = stringToAscii(vehicleNo).split(","); StringBuffer sbu = new StringBuffer(); for (int i = 0; i < chars.length; i++) { if(Integer.parseInt(chars[i]) > 31 && Integer.parseInt(chars[i]) != 127){ if(i != chars.length - 1) { sbu.append(Integer.parseInt(chars[i])).append(","); } else { sbu.append(Integer.parseInt(chars[i])); } } } value = asciiToString(sbu.toString()); return value; } /** * String转ASCII * */ private String stringToAscii(String value) { StringBuffer sbu = new StringBuffer(); char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if(i != chars.length - 1) { sbu.append((int)chars[i]).append(","); } else { sbu.append((int)chars[i]); } } return sbu.toString(); } /** * ASCII转String * */ private String asciiToString(String value) { StringBuffer sbu = new StringBuffer(); String[] chars = value.split(","); for (int i = 0; i < chars.length; i++) { sbu.append((char) Integer.parseInt(chars[i])); } return sbu.toString(); }