The number of individual lines from a txt file in C #

I have a txt document that contains more than 14,000 lines, many of which are duplicates, can I count the number of unique records?

+4
source share
3 answers

This is just a One-Liner:

var lines = File.ReadAllLines("FileToRead.txt").Distinct().Count(); 

Edit: But be careful with such decisions. Files larger than 600 MB may have problems.

+3
source

You can use the File.ReadLines Method and LINQ Distinct and Count Extension Methods :

 var result = File.ReadLines("input.txt").Distinct().Count(); 
+10
source

Iterate through the file, save what you find in the collection, ignore already analyzed records and in the end just check the size of the collection.

-1
source

Source: https://habr.com/ru/post/1382284/


All Articles