使用字符串生成器,我已经读取了一个文件..如何找到文件中是否存在给定的字符串?

369*_*692 2 .net c# c#-3.0 c#-4.0

我在StringBuilder中读了一个文件.当我给一个字符串作为输入时,如果文件中存在该单词,则输出应为true ..如果它不存在,则应该为false ..我该怎么做?有人可以帮我代码吗?我已经把程序写到了这里..我怎么走得更远?非常感谢.. :)

class Program
{
    static void Main(string[] args)
    {
        using (StreamReader Reader = new StreamReader("C://myfile2.txt"))
        {
            StringBuilder Sb = new StringBuilder();
            Sb.Append(Reader.ReadToEnd());
            {
                Console.WriteLine("The File is read");   
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 5

单行怎么样:

 bool textExists = System.IO.File.ReadAllText("C:\\myfile2.txt").Contains("Search text");
Run Code Online (Sandbox Code Playgroud)

这应该够了吧 :)