aspose file tools*
The moose likes Beginning Java and the fly likes about StringTokenize===> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about StringTokenize===>" Watch "about StringTokenize===>" New topic
Author

about StringTokenize===>

David Huang
Greenhorn

Joined: Jan 22, 2005
Posts: 4
I have the following code:

do analyze(String s){

StringTokenizer st = new StringTokenizer(s, "/" ,false);

this.address = st.nextToken();
this.dateq=Integer.parseInt(st.nextToken());
}

what if the passing String 's' dosen't contain '/'?

then I will get an empty set of variables..

is it possible to check whether the String s contains '/' then proceed my code ...?

I am a java beginner, can anyone just tell the exact code of doing that?


Many thanks



Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
If the String doesn't contain a '/' the whole String will be returned from the first call to nextToken().

You can test for a '/' in the string with the following


You can also get the number of tokens by calling countTokens() on the StringTokenizer
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
StringTokenizer st = new StringTokenizer(s, "/" ,false);

this.address = st.nextToken();
this.dateq=Integer.parseInt(st.nextToken());
}

what if the passing String 's' dosen't contain '/'?


The StringTokenizer constructor that you are using won't return any token including '/' character, because of the third argument in constructor which is false. The second argument is used to denote delimiters/separators between the tokens.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about StringTokenize===>
 
Similar Threads
hast table and unlimited looping
Bytes retrieval
sting tokenizer in a loop(vv urgent)
Doubt about StringTokenizer !!
Extracting certain values from a string