Remove Duplicate Lines From Text File?

后端 未结 5 2212
孤街浪徒
孤街浪徒 2020-12-09 05:58

Given an input file of text lines, I want duplicate lines to be identified and removed. Please show a simple snippet of C# that accomplishes this.

5条回答
  •  眼角桃花
    2020-12-09 06:32

    For small files:

    string[] lines = File.ReadAllLines("filename.txt");
    File.WriteAllLines("filename.txt", lines.Distinct().ToArray());
    

提交回复
热议问题