Topic: HasMoreTokens该怎么用 ?

  Print this page

1.HasMoreTokens该怎么用 ? Copy to clipboard
Posted by: heartache
Posted on: 2006-03-26 15:28

String quote3="asdadewrtafrghhacc124a445";
   st3=new StringTokenizer(quote3,"a");
   while(HasMoreTokens)
   System.out.print("after replace of quote3:"+st3.nextToken());
   //用a做分解字符串的标记,就是输出的字符不含有a这个字母,该怎么操作 ?

2.Re:HasMoreTokens该怎么用 ? [Re: heartache] Copy to clipboard
Posted by: why
Posted on: 2006-03-26 21:00

while (st3.hasMoreTokens()) {

check http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html

3.Re:HasMoreTokens该怎么用 ? [Re: heartache] Copy to clipboard
Posted by: ranchgirl
Posted on: 2006-03-27 00:17

A simple example here:


import java.util.*;
public class Test
{
public static void main(String[] args)
{
int idx = 0; int tokenCount;
String words[] = new String [500];
String message="The text of the message to be broken up for analysis";
StringTokenizer st = new StringTokenizer(message);
tokenCount = st.countTokens();
System.out.println("Number of tokens = " + tokenCount);
while (st.hasMoreTokens()) // make sure there is stuff to get
{ words[idx] = st.nextToken(); idx++; }
for (idx=0;idx<tokenCount; idx++)
{ System.out.println(words[idx]); }
}
}

4.Re:HasMoreTokens该怎么用 ? [Re: heartache] Copy to clipboard
Posted by: heartache
Posted on: 2006-03-27 18:20

我的问题解决了,谢谢斑竹


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923