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)
单行怎么样:
bool textExists = System.IO.File.ReadAllText("C:\\myfile2.txt").Contains("Search text");
Run Code Online (Sandbox Code Playgroud)
这应该够了吧 :)
| 归档时间: |
|
| 查看次数: |
13040 次 |
| 最近记录: |