*
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Reading words in a phrase without Tokenizer

greg burgess
Greenhorn

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
Greg
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:
indexOf()
length()
substring()
hope that helps


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reading words in a phrase without Tokenizer
 
Similar Threads
Finding Acronyms In a Text File
Still Stacks
Reading words from a file
Scanning a text file
Finding Most Common Phrase Occurance In String?