一种简单的方法是使用不带参数的string.Split(按空格字符分割):
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
string line = sr.ReadLine();
string[] words = line.Split();
foreach(string word in words)
{
foreach(Char c in word)
{
// ...
}
}
}
}
让我知道,如果你有任何问题。