//去除字符串所有换行和空格 private String fixString(String str){ String dest = ""; if (str!=null) { Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(""); } return dest; } //为字符串中的数据添加% private String stringAddChar(String check){ StringBuffer sb =new StringBuffer(check); int x=0; for(int i=0;i<sb.length();i++){ if(Character.isDigit(sb.charAt(i)) || '.'== sb.charAt(i)){ if(i==sb.length()-1){ sb.append('%'); i++; }else{ x=1; //非汉字状态 } continue; }else{ if(x==1){ x=2; //可插状态 }else{ x=0; //汉子状态 } if(x==2){ sb.insert(i, "%"); i++; //插入%后,sb的长度增长一位,i++跳过判断增长的这个% } } } check = sb.toString(); return check; }