我有一个txt文档,有超过14000个不同的行,其中许多是重复的,是否可以计算唯一条目的数量?
您可以使用File.ReadLines方法和LINQ的Distinct和Count Extension方法 :
var result = File.ReadLines("input.txt").Distinct().Count();
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.
遍历文件,保存您在集合中找到的内容,忽略已经分析的条目,最后只需检查集合的大小。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.