当前位置: 技术问答>java相关
关于:import java.util.StringTokenizer; 问题!
来源: 互联网 发布时间:2015-01-15
本文导语: String a="a,b,c,d,e"; 我想取出b或c, 注意: a,b,c,d,e 长度不等? 使用: import java.util.StringTokenizer; StringTokenizer b = new StringTokenizer(a,","); while(b.hasMoreTokens()) out.print(b.nextToken()); 这是按顺序打...
String a="a,b,c,d,e";
我想取出b或c,
注意: a,b,c,d,e 长度不等?
使用:
import java.util.StringTokenizer;
StringTokenizer b = new StringTokenizer(a,",");
while(b.hasMoreTokens())
out.print(b.nextToken());
这是按顺序打印出 A,B,C,D,E
我只想取B ,我该怎么取?
我想取出b或c,
注意: a,b,c,d,e 长度不等?
使用:
import java.util.StringTokenizer;
StringTokenizer b = new StringTokenizer(a,",");
while(b.hasMoreTokens())
out.print(b.nextToken());
这是按顺序打印出 A,B,C,D,E
我只想取B ,我该怎么取?
|
不好意思我写错了,应该是
String b = a.substring(a.indexOf(",")+1,a.indexOf(",",a.indexOf(",")+1));
或
StringTokenizer _st = new StringTokenizer(a,",");
String[] _s = new String[_st.countTokens()];
int i = 0;
while(_st.hasMoreTokens())
{
_s[i++] = _st.nextToken();
}
返回数组中的某一项
String b = a.substring(a.indexOf(",")+1,a.indexOf(",",a.indexOf(",")+1));
或
StringTokenizer _st = new StringTokenizer(a,",");
String[] _s = new String[_st.countTokens()];
int i = 0;
while(_st.hasMoreTokens())
{
_s[i++] = _st.nextToken();
}
返回数组中的某一项