15,560,045 members
See more:
i have to create 2 text files in c#.and there is some lines in two files. some lines are same. some lines are completely differnt. some lines are partially similar. and then read the data from those files. and need 4 buttons for comparison.each button has a question and click on that button will give the ans in a label or text box.
the question for comaparison are below.

1. how many lines are similar.
2. how many lines are partial similar(match some character).
3.how many lines are dissimilar according to wordcoundwise.
4. how many lines are dissimilar according to wordwise.

Posted

## Solution 4

So, you have a GUI app with some buttons and some result display area.

Let's now focus on the business logic.
It consists of
- GetNumberOfEqualLines(...)
- GetNumberOfPartiallyEqualLines(...)
- etc.

If you find a library that provides the comparison functionality, use it in the above mentioned functions.

If you have no such library, implement it yourself.
The trouble with comparing is the algorithm to synchronize after a mismatch.

Assume you compare from begin to end of the two files: at one point you reach a line in both files where you have a mismatch. Does the line is *missing* in the 1st/2nd file or are the lines not missing but *partially* equal?

E.g. comparing the two files

 ```ab ac ad``` ```ab xx yy ad```

You have to decide if a line is missing or if it is a partial match.

Think of how to achieve that. Write the cases down on paper and try to simulate the situations.

Depending on the size of the data and the needed "accuracy", you might come up with some context range where you search for a synchronization point. E.g. if you say you search at a mismatch for the next N lines for a matching in both files. The nearest match is taken and the lines between are different (or partially equal).

At this point you get into an interesting interview discussion... ;-)

Good luck!

Cheers
Andi

## Solution 2

Hi,

In my Tip/Trick i have created one API for comparison of two text messages for similarity. you can find it Here[^]

From above example you can get some idea about how you can achieve your goal. you need to create two text reader for two file comparison. After each of the read method call you can compare both the line and increment the counter depending on the button click event.

if you would like to create this utility then you need knowledge in File Handling. Please check this article[^] to understand file handling in c#.

Thanks
-Amit Gajjar