当前位置: 技术问答>java相关
关于字符串分割!高手请进!
来源: 互联网 发布时间:2015-08-07
本文导语: 如: String a="123;4324;432;4324;432;432;432"; in jsp 用什么语句生成b[0]="123",b[1]="4324".......? | public static String[] StringToStringArray(String attribName,String compartChar){ int paraNum=0; String tempStr=attribName; while(tempStr....
如:
String a="123;4324;432;4324;432;432;432";
in jsp 用什么语句生成b[0]="123",b[1]="4324".......?
String a="123;4324;432;4324;432;432;432";
in jsp 用什么语句生成b[0]="123",b[1]="4324".......?
|
public static String[] StringToStringArray(String attribName,String compartChar){
int paraNum=0;
String tempStr=attribName;
while(tempStr.indexOf(compartChar)!=-1){
tempStr=tempStr.substring(tempStr.indexOf(compartChar)+1);
paraNum++;
}
paraNum++;
String[] S2SA=new String[paraNum];
int i=0;
int pos=0;
while(attribName.indexOf(compartChar)!=-1){
pos=attribName.indexOf(compartChar);
S2SA[i]=attribName.substring(0,pos);
attribName=attribName.substring(pos+1);
i++;
}
S2SA[i]=attribName;
return S2SA;
}
int paraNum=0;
String tempStr=attribName;
while(tempStr.indexOf(compartChar)!=-1){
tempStr=tempStr.substring(tempStr.indexOf(compartChar)+1);
paraNum++;
}
paraNum++;
String[] S2SA=new String[paraNum];
int i=0;
int pos=0;
while(attribName.indexOf(compartChar)!=-1){
pos=attribName.indexOf(compartChar);
S2SA[i]=attribName.substring(0,pos);
attribName=attribName.substring(pos+1);
i++;
}
S2SA[i]=attribName;
return S2SA;
}
|
String str = "123;4324;432;4324;432;432;432";
StringTokenizer st=new StringTokenizer(str,";");//分界符“/”
int count=st.countTokens();
String[] strArray=new String[count];
int i=0;
while(st.hasMoreTokens()){
strArray[i]=st.nextToken();
out.println(strArray[i]);
i++;
}
StringTokenizer在java.util.*包里
StringTokenizer st=new StringTokenizer(str,";");//分界符“/”
int count=st.countTokens();
String[] strArray=new String[count];
int i=0;
while(st.hasMoreTokens()){
strArray[i]=st.nextToken();
out.println(strArray[i]);
i++;
}
StringTokenizer在java.util.*包里