日期:2014-05-20  浏览次数:20760 次

好久不发帖了
要将
[01:43.59]See   the   pretty   people   play
[01:48.02]Hurrying   under   the   light,

中的时间去掉,下面是我编的不知道是那个地方错了。。。


//import   java.util.regex.*;
import   java.util.*;
import   java.io.*;
public   class   Replace{
public   static   String   readFile(String   s)throws   Exception{
String   backText=null;
String   temp;
BufferedReader   br=new   BufferedReader(
new   FileReader(s));
while((temp=br.readLine())!=null){
backText+=temp;
backText+= "\n ";
}
//System.out.println(backText);
return   backText;
}
public   static   void   main(String[]   args)throws   Exception{
String   fromText=readFile(args[0]);
//Matcher   m=Pattern.compile( "[.*] ").matcher(s);
fromText=fromText.replaceAll( "/[.*]/ ", "   ");
PrintWriter   pw=new   PrintWriter(new   FileWriter( "c:\\outputFile.txt "));
pw.println(fromText);
pw.close();
}
}  


------解决方案--------------------
import java.util.*;
import java.io.*;
public class Replace{
public static String readFile(String s)throws Exception{
String backText=null;
String temp;
BufferedReader br=new BufferedReader(
new FileReader(s));
while((temp=br.readLine())!=null){
backText+=temp;
backText+= "\n ";
}
//System.out.println(backText);
return backText;
}
public static void main(String[] args)throws Exception{
String fromText=readFile(args[0]);
fromText=fromText.replaceAll( "\\[[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}\\] ", " ")); ////修改
PrintWriter pw=new PrintWriter(new FileWriter( "c:\\outputFile.txt "));
pw.println(fromText);
pw.close();
}
}

------解决方案--------------------
抱歉,把[01:43.59]看成了[01:43:59],
修改成fromText.replaceAll( "\\[[0-9]{2}\\:[0-9]{2}\\.[0-9]{2}\\] ", " "),
测试过这个:
String fromText= "[01:43.59]See the pretty people play [01:48.02]Hurrying under the light ";
fromText=fromText.replaceAll( "\\[[0-9]{2}\\:[0-9]{2}\\.[0-9]{2}\\] ", " ");
System.out.println(fromText);
结果是“ See the pretty people play Hurrying under the light”