且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 CSV 中删除行

更新时间:2023-12-03 21:13:58

这是一个基于 5 个逗号标准的简单解决方案

Here's a simple solution based on your 5 commas criteria

List<String> lines = new List<string>();
string line;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");

while ((line = file.ReadLine()) != null)
{
    lines.Add(line);
}

lines.RemoveAll(l => l.Contains(",,,,,"));

然后你可以把它写回来或者随便你

Then you can write it back out or whatever you'd like

写出来:

using (System.IO.StreamWriter outfile = new System.IO.StreamWriter(outputPath))
{
      outfile.Write(String.Join(System.Environment.NewLine, lines.ToArray()));
}