我试图找到一行包含一个特定的字符串,并打印整个行。StreamReader - 如何读取包含特定字符串的行?
这是我走到这一步:
using (StreamReader reader = process.StandardOutput)
{
string result;
string recipe;
while ((result = reader.ReadLine()) != null)
{
if (result.Contains("Recipe:"))
{
recipe = reader.ReadLine();
}
}
}
的问题是,这个代码将读取下一行,而不是包含字符串的行。如何阅读包含文字“食谱:”的行?
你已经在'result'中拥有了它。有什么问题? – SLaks