//先去除" ",得到"...................................."这样的一个字符串,然后再去除一头一尾的引号
public static void replaceChar(String s){
//String s = "01290943050280128550\" \"01\" \"0\" \"13548418074\" \"923041\" \"13548418074\" \"1862 \" \"1862SMS \" \"01\" \"0 \" \"0 \" \"0 \" \"0\" \"85 \" \"280 \" \"002801\" \" \" \"13800280500\" \"20070129094305\" \"20070129094314\" \"PXY08 \" \"0";
String ss = s.replaceAll("\" \"","");
System.out.println(" ss ="+ss);
ss = ss.replaceAll("\"","");
System.out.println(" ss ="+ss);
}
public static void readFile(){
try{
File file = new File("D:\\dosp\\t.txt");
java.io.FileReader reader = new FileReader(file);
BufferedReader br = new BufferedReader(reader);
String s = br.readLine();
System.out.println(" s = " + s);
replaceChar(s);
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
Test test = new Test();
readFile();
}
以下是在文本t.txt中的例子(处于一行,每个字段用引号括住,各个字段之间有空格)
"01282356000280118304" "01" "0" " " "923084" "13466390573" "5198 " "-GSSP " "03" "0 " "1500 " "DB:0115" "1" "101" " " "002801" " " "13800280500" "20070128235602" "20070128235602" "Agent0" "0 "
进过上面函数处理后得到:
第一步得到:
"01282356000280118304010 923084134663905735198 -GSSP 030 1500 DB:01151101 002801 138002805002007012823560220070128235602Agent00 "
第二步得到:
01282356000280118304010 923084134663905735198 -GSSP 030 1500 DB:01151101 002801 138002805002007012823560220070128235602Agent00