读取一个strsql=strsql+" select * from table ";strsql=strsql+" where cola=a ";strsql=strsql+" and colb=b ";之类的文本   把前面的strsql=strsql+"  和后面的";  都灭了 ;写如一个新的文本
微微详细点,初学java。修改的要吐了。谢谢
解决马上结贴。分不够可以加的

解决方案 »

  1.   

    就是把前面的  strsql=strsql+"    和后面的";  给删除了  每行的
      

  2.   

    写个简单的正则
    对你读进来的每一行,执行者个语句a为你读入的字符串a = a.replaceAll("^.*\"|\";","");
      

  3.   

    楼上的正则有问题,没有考虑贪婪问题偶有空,给你写了段代码:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.regex.PatternSyntaxException;public class SqlGetter { public static void main(String[] args) {
    String str = "strsql=strsql+\" select * from table \";";
    System.out.println(getSqlStr(str));
    } public static String getSqlStr(String sqlLine) {
    String patternString = "^.*?\"|\";$";
    Pattern pattern = null;
    try {
    pattern = Pattern.compile(patternString);
    } catch (PatternSyntaxException e) {
    System.out.println("Pattern syntax error");
    return sqlLine;
    }

    Matcher matcher = pattern.matcher(sqlLine);
    return matcher.replaceAll("");
    }}
      

  4.   

    呀 我其实是不知道如何  逐行读入的  正则表达式  很好
    我的意思是从  1.txt  读取  到  2.txt  改好的
    嗯  我比较弱
    还是谢谢楼上的热心人的
      

  5.   

    import java.io.RandomAccessFile;public class DumpFile {
    public static void main(String[] args) throws Exception {
    RandomAccessFile f1 = new RandomAccessFile("c:/temp/1.txt", "r");
    RandomAccessFile f2= new RandomAccessFile("c:/temp/2.txt", "rw");
    while(true){
    String lineText = f1.readLine();
    if(lineText==null){
    break;
    }
    f2.writeBytes(lineText.replaceAll("^.*?\"|\";$" ,"") + "\r\n");
    }
    f2.close();
    f1.close();
    }
    }