Comparison of two text files inside RichTextBoxes in C#


  • hi friends,
    I am developing a Comparison tool in C#. can anyone give me any idea to start with the comparison.
    Task Details:
    I am using C#2008. I want to compare two text files and wherever the diffrences in both the files it should be highlighted.
    My work:
    I am creating a windows application in c# where I am having two RichtextBoxes. I have loaded the file1 in 1st and file2 in 2nd Rich Text Box. Now I want to highlight the differences in RTB2 whereever It finds difference in first.
    I have started with the comparison where 
    I am comparing line by line (1 line from RTB1 and 1 line from RTB2); but in this case my logic is being fail; because 
    1. If the number of lines differnces in both the files.
    2. If lines moved from its position to another inside the same file.
    3. If new lines inserted or deleted in 2nd RichTextBox; then it finds first difference
    and highlighting that line but after that it is not matching any lines i.e. highligting each line as a difference in both the files. because of different number of lines.
    NOTE : If anybody used Epsilon S/w.....then this s/w provides this type of functionality. here it is providing character by character comparison and currsor always stopped
    when find differences in both files and showing the message "Difference Found". when again start comparision(Ctri+F2) then againg it shows next difference. and so on.......

    I have searched over Internet but didn't find anything. There are some tools provided on internet but I can't use the tools because of some restriction ... so I have to develop my own. I have also searched for algorithm for this purpose but unable to find it.
    Can anybody give me basic idea about how to start with this thing..... Please help me in this issue.
    Thanks & Regards,

    Thursday, July 17, 2014 5:14 AM


All replies