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

zhanghongwei 2001-05-17 02:37:00
有关java.util.StringTokenizer的一个能用的例子。谢谢!
...全文
98 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧