I have a text file containing just lowercase letters and no punctuation except for spaces. I would like to know the best way of reading the file char by char, in a way that
I would do something like this:
IEnumerable ReadWords(StreamReader reader)
{
string line;
while((line = reader.ReadLine())!=null)
{
foreach(string word in line.Split(new [1] {' '}, StringSplitOptions.RemoveEmptyEntries))
{
yield return word;
}
}
}
If to use reader.ReadAllText it loads the entire file into your memory so you can get OutOfMemoryException and a lot of other problems.