哪位大虾能给一个StringTokenizer的例子?

zhanghongwei 2001-05-17 02:37:00
有关java.util.StringTokenizer的一个能用的例子。谢谢!
...全文
71 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhanghongwei2 2001-05-18
aa
回复
要是我想把空格换成字符A,只要初始化参数变化就可以了。
import java.util.*;
class stk
{
public static void main(String[] args)
{
System.out.println("Hello World!");
StringTokenizer st = new StringTokenizer("this is a test","a");
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}

}
}
请看这段javadoc :
StringTokenizer
public StringTokenizer(String str,
String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Parameters:
str - a string to be parsed.
delim - the delimiters.
回复
试试这个:
import java.util.*;
class stk
{
public static void main(String[] args)
{
System.out.println("Hello World!");
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}

}
}
我输出的结果是正确的:
Hello World!
this
is
a
test
回复
zhanghongwei 2001-05-18
这个我试过了输出的是this is a test!!!!!不换行!
还有,要是我想把空格换成字符A,怎么办?谢谢!
回复
The following is one example of the use of the tokenizer. The code:

StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
println(st.nextToken());
}

prints the following output:

this
is
a
test


Since:
JDK1.0
多看看javadoc
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-05-17 02:37
社区公告
暂无公告