• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Reading words in a phrase without Tokenizer

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!