我試圖找到一行包含一個特定的字符串,並打印整個行。StreamReader - 如何讀取包含特定字符串的行?
這是我走到這一步:
using (StreamReader reader = process.StandardOutput)
{
string result;
string recipe;
while ((result = reader.ReadLine()) != null)
{
if (result.Contains("Recipe:"))
{
recipe = reader.ReadLine();
}
}
}
的問題是,這個代碼將讀取下一行,而不是包含字符串的行。如何閱讀包含文字「食譜:」的行?
你已經在'result'中擁有了它。有什麼問題? – SLaks