NEWBIE - Loop Through each WORD in a text file

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Greetings,

How can I loop through each word in a text file? Something like:

For Each Word in mytextfile.txt
Do Something
Next

But, I'm not sure how to do this. Any help out there?
 
//Not Tested
Dim Input as String
dim SplitInput() as string
do while mytextfile.peek() <> -1
Input = mytextfile.readline
SplitInput = String.Split(" "c) 'Splits on "space"
For each Input in SplitInput
debug.writeline(Input)
Next
loop

That's the general idea. There are lots of ways to read in the file This
one just reads in one line at a time. You could read in char by char and
look for the space too. If you need to know how to open/read the file look
at the System.IO.TextReader class.

Chris
 
Greetings,

How can I loop through each word in a text file? Something like:

For Each Word in mytextfile.txt
Do Something
Next

But, I'm not sure how to do this. Any help out there?


How are the words separated? By a space?

Take a look at the System.IO classes. There are several classes such as the
TextReader classes which can be used to read a line of text. Once you have
a line of text, you could use te split method to parse the string based on
the space.
 
Dave said:
How can I loop through each word in a text file? Something like:

For Each Word in mytextfile.txt
Do Something
Next

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

When reading the lines, you'll have to split them up into the words. To do
this, you can use appropriate functions ('Split', 'Mid', ...) provided in
'Microsoft.VisualBasic.Strings.*'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top