Reputation: 139
I have a txt document which has over 14000 different lines many of these are duplicates, is it possible to count the number of unique entries?
Upvotes: 4
Views: 1374
Reputation: 12458
It's a simply "One-Liner" like that:
var lines = File.ReadAllLines("FileToRead.txt").Distinct().Count();
Edit: But take care with those kind of solutions. With files larger than 600 MB you might get problems.
Upvotes: 3
Reputation: 1389
Iterate through the file, save what you find in a collection, ignore already analyzed entries and in the end, just check the size of the collection.
Upvotes: -1
Reputation: 217263
You can use the File.ReadLines Method and LINQ's Distinct and Count Extension Methods:
var result = File.ReadLines("input.txt").Distinct().Count();
Upvotes: 11