Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am having a list containing 10 lines.

I need to compare these lines with a text file and find the occurrence of these line and increase their count

If I have 10 line.
I need to have 10 count variables so that it counts repeated lines.

How to do this
Posted

1 solution

1.In place of your list and counts you could create a class that contains two properties: StringForSearch and Occurrence (counter) then you could create the List of this object types;

2.For reading the file you could use StreamReader to read line by line like in the next example
C#
using (StreamReader reader = new StreamReader("file.txt"))
{
            string line;
	    while ((line = reader.ReadLine()) != null)
	    {
		CompareLine(line, listOfStrings);
	    }
}

3.For comparing just pass the line read above to a method that use the list from the 1st point to search your initial text and to increment the counters for matching.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900