여러 줄이 포함 된 텍스트 파일이 있는데 그 중 많은 줄이 중복됩니다.텍스트 파일의 줄을 순위순으로 표시
내가 가장 나타나는 사람은 상단과 하단에 적어도 표시되는 목록을 묘사합니다.
그러나 목록에 문자열이 몇 번 표시되는지 표시하고 싶습니다.
어떻게 이렇게 가겠어요? 파일이 너무 커서 아닌 경우 메모리에 들어갈 수있는 경우에 저장할 수 있습니다, 즉,
using(StreamReader sr = new StreamReader("my file")) {
Dictionary<string, int> items = new Dictionary<string, int>();
while(sr.BaseStream.Position < sr.BaseStream.Length) {
string s = sr.ReadLine();
if(items.ContainsKey(s)) {
items[s]++;
} else {
items.Add(s, 1);
}
}
// You now have a dictionary of unique strings and their counts - you can sort it however you need.
}
나는이 사용할 수 없습니다 - 프레임 워크 4.0? – qwertyuywertwer
예 - 죄송합니다. 수정 : pls now now – kol
LINQ 부분도 제거해야했습니다. .NET 3.5에 나타났습니다. – kol