D
D
DenyDream2021-08-08 17:22:51
C++ / C#
DenyDream, 2021-08-08 17:22:51

How to delete identical lines in a file, while leaving one of them?

How to delete identical lines in a file, while leaving one of them? Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2021-08-08
@DenyDream

var lines = File.ReadAllLines(pathToFile);
var disctinctLines = lines.Distinct();
File.WriteAllLines(pathToFile, disctinctLines);

Works for files that fit in memory.

D
Developer, 2021-08-08
@samodum

Dictionary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question