Jump to content
  • Advertisement
Sign in to follow this  
chrisliando

[.net] How does the WinMerge/WinDiff works and how to give highlight color to a block of tex

This topic is 3877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to develop a text comparer similar to WinMerge or WinDiff. 1. I'd like to know how WinDiff / WinMergeworks to compare 2 files and found the difference. 2. How to give highlight color to text blocks which is differ each other? I just need to show the difference between 2 files and mark them with highlight color. So not all WinDiff features I need. Thank you very much..

Share this post


Link to post
Share on other sites
Advertisement
On a very basic level you can have two textboxes.

Loop through the text in textbox1.Text a character at a time and compare it to textbox2.Text. Everytime textbox1.Text != textbox2.Text then hilight the text.

Most text comparing software allows you to adjust the offset it checks. So you can have textbox1.Text != textbox2.Text[i + Offset] to hilight. Offset can be a variable that can be set using buttons in your GUI to Offset-- or Offset++.

Finally to have the hilighting you need you will need to use richtextbox's instead of textboxes.

To hilight a character that is different use the following:

for(int i=0; i<richTextBox1.Text.Length && i<richTextBox2.Text.Length; i++)
{
if(richTextBox1.Text != richTextBox2.Text)
{
richTextBox1.SelectionStart = i;
richTextBox1.SelectionLength = 1;
richTextBox1.SelectionColor = Color.Red;
richTextBox2.SelectionStart = i;
richTextBox2.SelectionLength = 1;
richTextBox2.SelectionColor = Color.Red;
}
}


Please remember that Google is your friend. Don't be afraid to use Google to search for answers before you ask here.

Share this post


Link to post
Share on other sites
Wikipedia's article on the longest common subsequence problem presents a pseudo-code algorithm that can be used to calculate the 'diff' between two files.

It uses a recursive method; you'll need to convert it to an iterative method if you wish to avoid StackOverflowExceptions. [smile]

Share this post


Link to post
Share on other sites
Is it enough to use only the algorithm you gave me to check a very long text file?

I also have other problem which is how to display unicode characters? I need to display Japanese Kanji, Hiragana, Katakana, Chinese, Korean and Thai characters in the proper way..

I have tried this way:

textBox2->Text = System::IO::File::ReadAllText(openFileDialog1->fileName, System::Text::Encoding::Unicode);

but it still cannot display the text file containing Japanese Kanji / Hiragana / Katakana well and WORSE, a text file containing Latin characters also displayed as Asian characters but I don't know what characters they were.

Can you please tell me how to display all text file well?

Thank you very much.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!