我希望能够写出类似下面的东西。有人可以告诉我如何用 C# 编写一个干净的 WordReader 类。一句话就是[a-zA-Z]+
。
public List<string> GetSpecialWords(string text)
{
string word;
List<string> specialWords = new List<string>();
using (WordReader wr = new WordReader(text))
{
while (true)
{
word = wr.Read();
if (word == null) break;
if (isSpecial(word)) specialWords.Add(word);
}
}
return specialWords;
}
private bool isSpecial(string word)
{
//some business logic here
}