wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Reading words in a phrase without Tokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading words in a phrase without Tokenizer" Watch "Reading words in a phrase without Tokenizer" New topic

Reading words in a phrase without Tokenizer

greg burgess

Joined: Nov 28, 2001
Posts: 3
Hi guys I'm looking for somehelp to select words from a text file and then compare the size of each word(vector class I guess) But the key issue is that I cannot!!! use a StringTokenize.
I've managed to put the file (now a String) into an array count the number of spaces (as case) and vowels but to pick out each word what should I do. I previously worked out how to pick out the first and last words in a short phrase using a while loop of while(loopIndex >=0&&line.charAt(loopIndex) !=' '). What can I change to pick out each word in turn???
Yours Greg
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
this sounds like a homework assignment so I'll give you a push in the right direction...
I assume your defining a word as anything surrounded by whitespace?
your steps would be this:
read in a line into a String
while you haven't reached the end of the String
find the index of the next whitespace
everything between that index and the previous one is a word
do what ever you need to do with the word
done looping
you need a couple,of index variables to keep track of the current and previous index of whitespace characters. Some of the String methods to look at are:
hope that helps

Sun Certified Programmer for the Java� 2 Platform

wood burning stoves
subject: Reading words in a phrase without Tokenizer
It's not a secret anymore!