There is a much better way to do this: string.Split() : if you read the entire line, C # can automatically split it into each space:
string[] words = reader.ReadToEnd().Split(' ');
Now the words array contains all the words in the file, and you can do whatever you want with them.
In addition, you may need to learn the File.ReadAllText method in the System.IO namespace - this can make your life much easier to import files into text.
Edit: I assume this assumes that your file is not shockingly large; as long as all things can be reasonably read in memory, this will work most easily. If you have gigabytes of read data, you probably want to avoid this. I would suggest using this approach if possible: it makes better use of the structure that you have at your disposal.
source share