您的位置:程序门 -> java -> j2se / 基础类



好久不发帖了


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


好久不发帖了[已结贴,结贴人:biaoflying]
发表于:2007-03-29 12:37:54 楼主
要将
[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();
}
}  
发表于:2007-03-29 13:13:231楼 得分:10
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();
}
}  
发表于:2007-03-29 15:28:522楼 得分:0
好像不行啊,不知道你运行了没。
发表于:2007-03-29 21:21:323楼 得分:10
抱歉,把[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”
发表于:2007-03-31 16:55:254楼 得分:0
谢谢


快速检索

最新资讯
热门点击