Java 正则表达式自义bean

1/5/2008来源:Java教程人气:5135


  java 正则表达式自义bean

1.因为jdk1.4以下String类未曾使用split 方法,所以为了能够在jdk1.3以下的版本使用,正义了如下类



package pubBean;

import java.util.*;

/**

*

* <p>Title: </p>

* <p>Description:通过分解符分解由特定字符分开的字符串,并把返回一个数组假如 </p>

* <p>Copyright: Copyright (c) 2004</p>

* <p>Company: </p>

* @author 丁小龙

* @version 1.0

*/

public class Patten {

Vector arravl=new Vector();

String compchar;

public Patten() {

try {

jbInit();

} catch (Exception ex) {

ex.PRintStackTrace();

}

}

private Vector split(String src,String charat,String self){



int len=src.indexOf(charat);

if(len==-1&&src=../../=null)

return arravl ;

if(len==-1){

arravl.addElement(src);

return arravl;

}else

arravl.addElement(src.substring(0,len));

return split(src.substring(len+charat.length(),src.length()),charat,self);

}

public String[] split(String src,String charat){

arravl.removeAllElements();

Vector retvec=split( src,charat,"1");

if(retvec.size()==0retvec==null)

return null;

String []arrret=new String[retvec.size()];

for(int i=0;i<retvec.size();i++){

arrret[i]=(String)retvec.elementAt(i);

}



return arrret;

}



public void compile(String com){

this.compchar=com;

}



public String[] split(String src){

arravl.removeAllElements();

String comch="";

if(this.compchar==null){

comch=",";

}else{

comch=this.compchar;

}

Vector retvec=split( src,comch,"1");

if(retvec.size()==0retvec==null)

return null;

String []arrret=new String[retvec.size()];

for(int i=0;i<retvec.size();i++){

arrret[i]=(String)retvec.elementAt(i);

}



return arrret;

}



private void jbInit() throws Exception {