Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:56:02+00:00 2026-05-24T07:56:02+00:00

I am looking to compare 2 files using RichTextBoxes and upload them into new

  • 0

I am looking to compare 2 files using RichTextBoxes and upload them into new RichTextBoxes with the certain text that is the same in green and the different text in red.

What I mean is:

DOCUMENT 1

C1    147417 111.111 222.222 0 TEXT
U13   IC-123456 1234 9876 360 TEXT
R123 13866 -99.9 123.456 100 TEXT
U24   IC-123456 -14 -50 90 TEXT
............more lines............

DOCUMENT 2

1   U13  IC-123456   SOMETEXT   1.00   EA P C n   Y
                     EC5547,3-UP                 50
1   U24  IC-123456   SOMETEXT   1.00   EA P C n   Y
                     EC5547,3-UP                 50
1   C1  147417   TEXT   2.00   EA P C n   Y
                 0603,EC0303             50
1   R123  138666   MORETEXT   2.00 EA P C n   Y
                                             50
......................more lines..........................

And I would like to match the 1st and 2nd columns in the first file to see if they exist on any line in the second file. If they match, the matched items would turn the matched text green and everything else red.

  • Is there anyway to do this?
  • How could I go about comparing the 1st to columns in a different file?
  • Is it possible to change the color of text in a RTB and not the entire line?

EDIT:

    private void checkMatchesInGCandBOM()
    {
        // Splits the text up to compare with the other text.
        var combinedSplit = combinedPlacementsRichTextBox.Text.Split('\n');

        string[] splitLines;

        foreach (var line in combinedSplit)
        {
            Match theMatch = Regex.Match(line, @"^.*");

            if (theMatch.Success)
            {
                // Stores the matched value in string output.
                string output = theMatch.Value;

                // Replaces the tabs with spaces.
                output = Regex.Replace(output, @"\s+", " ");
                splitLines = output.Split(' ');

                int pos = 0, pos2 = 0;
                pos = bomRichTextBox.Find(splitLines[0], pos, RichTextBoxFinds.MatchCase);
                pos2 = bomRichTextBox.Find(splitLines[1], pos2, RichTextBoxFinds.MatchCase);

                while (pos != -1)
                {
                    if (bomRichTextBox.SelectedText == splitLines[0] && bomRichTextBox.SelectedText != "")
                    {
                        int my1stPosition = bomRichTextBox.Find(splitLines[1]);
                        bomRichTextBox.SelectionStart = my1stPosition;
                        bomRichTextBox.SelectionLength = splitLines[0].Length;
                        bomRichTextBox.SelectionFont = new System.Drawing.Font("Arial", 8, FontStyle.Underline);
                        bomRichTextBox.SelectionColor = Color.Green;
                    }

                    pos = bomRichTextBox.Find(splitLines[0], pos + 1, RichTextBoxFinds.MatchCase);
                }

                while (pos2 != -1)
                {
                    if (bomRichTextBox.SelectedText == splitLines[1] && bomRichTextBox.SelectedText != "")
                    {
                        int my1stPosition = bomRichTextBox.Find(splitLines[0]);
                        bomRichTextBox.SelectionStart = my1stPosition;
                        bomRichTextBox.SelectionLength = splitLines[1].Length;
                        bomRichTextBox.SelectionFont = new System.Drawing.Font("Arial", 8, FontStyle.Underline);
                        bomRichTextBox.SelectionColor = Color.Blue;
                    }

                    pos2 = bomRichTextBox.Find(splitLines[1], pos2 + 1, RichTextBoxFinds.MatchCase);
                }
            }
        }

However, this does not seem to be working properly….!

All of the columns on the far left should have been COMPLETELY green but for some reason some are black and some are black and green. Also the next column should have been found everything and changed the color to complete blue..This is what it turned out to look like using the code above.

New screenshot of what happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:56:03+00:00Added an answer on May 24, 2026 at 7:56 am

    You’ll need to create a process that pulls the original values that you want line-by-line. It doesn’t look like your file is in a flat format and doesn’t use delimiters, so pulling those values might be a bit tricky… You mentioned in the comments that our data is space delimited. In this case you can do a split on spaces and create your search string with the first two elements of the array.

    Once you have a way to separate those columns from the rest of your document, cycle through and call something something like this:

    if (richTextBox2.Find(mystring)>0)
    {
        int my1stPosition=richTextBox1.Find(strSearch);
        richTextBox2.SelectionStart=my1stPosition;
        richTextBox2.SelectionLength=strSearch.Length;
        richTextBox2.SelectionFont=fnt;
        richTextBox2.SelectionColor=Color.Green;
    } 
    

    (code mostly taken from http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/651faf9b-ae32-4c99-b619-d3afd89477e1/)

    The “SelectionColor” basically tells the RTB to change the color of the selected text. You are making the program automatically select the text for you with “SelectionStart” and “SelectionLength”.

    Obviously change the font params to whatever you’d like. If you want to highlight the rest of the document red, you might want to consider making the new RTB red by default, since it sounds as if it’s only used for the comparison.

    The above will only work for the first occurrence. If you want it to highlight ALL occurrences, you might want to check out IndexOfAll. See this page for more info: http://www.dijksterhuis.org/manipulating-strings-in-csharp-finding-all-occurrences-of-a-string-within-another-string/

    IndexOfAll will return an array with a list of each position a substring lies in another string. Once you find these, loop through the array and use the same code that’s listed above to change the color of each set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a diff/compare tool that shows differing lines from two text files,
I am looking to compare two exe files. I should ensure that the existing
I'm trying to write a simple program that will compare the files in separate
I am looking for an editor/comparator for i18n property files that would help me
I am looking for a method to compare and sort UTF-8 strings in C++
Looking for an example that: Launches an EXE Waits for the EXE to finish.
Looking for a Linux application (or Firefox extension) that will allow me to scrape
Looking for feedback on : http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
Looking for C# class which wraps calls to do the following: read and write
Looking at what's running and nothing jumps out. Thanks!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.