当前位置: 技术问答>java相关
急!!!jsp中怎么将一个字符串拆分为数组?
来源: 互联网 发布时间:2015-04-17
本文导语: 如String str="A|B|C|D"; 要用"|"做分隔符,得到数组,怎么做! 用split不行啊! | import java.util.regex.Pattern; Pattern pttnComma,pttnDash; pttnComma=Pattern.compile(",|rn"); pttnDash=Pattern.compile("-"); String strPartIP[]=...
如String str="A|B|C|D";
要用"|"做分隔符,得到数组,怎么做!
用split不行啊!
要用"|"做分隔符,得到数组,怎么做!
用split不行啊!
|
import java.util.regex.Pattern;
Pattern pttnComma,pttnDash;
pttnComma=Pattern.compile(",|rn");
pttnDash=Pattern.compile("-");
String strPartIP[]=pttnComma.split(IPPool);
String strIP[]=pttnDash.split(strPartIP[0]);
java.util.regex.Pattern可能是jdk1.4新增的。
Pattern pttnComma,pttnDash;
pttnComma=Pattern.compile(",|rn");
pttnDash=Pattern.compile("-");
String strPartIP[]=pttnComma.split(IPPool);
String strIP[]=pttnDash.split(strPartIP[0]);
java.util.regex.Pattern可能是jdk1.4新增的。
|
sorry
StringTokenizer
StringTokenizer
|
用java.util.StringTokenizer类做,它返回一个Enumeration
StringTokenizer st = new StringTokenizer(str,"|");
int count = st.countTokens();
String[] strArray = new String[count];
for (int i = 0; i
StringTokenizer st = new StringTokenizer(str,"|");
int count = st.countTokens();
String[] strArray = new String[count];
for (int i = 0; i