我如何解析c#中的文本文件

4 c# parsing text-files

我如何解析c#中的文本文件?

CMS*_*CMS 8

检查这个有趣的方法,Linq To Text Files,非常好,你只需要一个IEnumerable<string>方法,产生每一个file.ReadLine(),然后你做查询.

是另一篇更好地解释相同技术的文章.


Per*_*vic 6

using (TextReader rdr = new StreamReader(fullFilePath))
{
  string line;

  while ((line = rdr.ReadLine()) != null)
  {
    // use line here
  }
}
Run Code Online (Sandbox Code Playgroud)

将变量"fullFilePath"设置为完整路径,例如.C:\ TEMP\myTextFile.txt