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 8452075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:24:33+00:00 2026-06-10T11:24:33+00:00

Basically, i have done my program so that it will display differences in strings

  • 0

Basically, i have done my program so that it will display differences in strings and display the whole line. I want to highlight (in a colour) the differences in the line.

Example:

Original at line 5
   <rect x="60.01" width="855.38" id="rect_1" y="-244.35" height="641.13" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: none; "/>

Edited at line 5
   <rect x="298.43" width="340.00" y="131.12" height="380.00" id="rect_1" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: rgb(255, 102, 0); "/>

In this example, the width is different from the ‘original’ from the ‘edited’ version. I would like to be able to highlight that difference and any other difference.

My code so far:

Patch patch = DiffUtils.diff(centralFile, remoteFile);
        StringBuffer resultsBuff = new StringBuffer(remoteFileData.length);
        for (Delta delta : patch.getDeltas())
            {
            resultsBuff.append("Original at line " + delta.getOriginal().getPosition() + "\n");
            for (Object line : delta.getOriginal().getLines())
                {
                resultsBuff.append("   " + line + "\n");
                }
            resultsBuff.append("Edited at line " + delta.getRevised().getPosition() + "\n");
            for (Object line : delta.getRevised().getLines())
                {
                resultsBuff.append("   " + line + "\n");
                }
            resultsBuff.append("\n");
            }
        return resultsBuff.toString();
        }

That will display two whole lines like the example before (the original and the edited version) I want to be able to highlight the changes that have actually been made, is there any way to do this in Java?

  • 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-06-10T11:24:35+00:00Added an answer on June 10, 2026 at 11:24 am

    Any particular reason why you are trying to rewrite common tools like WinDiff and Beyond Compare?
    In case you really need it:
    the main difficulty is finding where the differences stop
    <rect x="60.01" width="855.38" id="rect_1" y="-244.35" height="641.13" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: none; "/>
    <rect x="298.43" width="340.00" y="131.12" height="380.00" id="rect_1" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: rgb(255, 102, 0); "/>

    What would you consider to be the difference?
    1) changed value of “x” and “width” are easy – they come in the same sequence
    2) what do you think happened to “id” and it’s value? how do you want to highlight it?

    Assuming that you always know which is the “original”
    I suggest you scan the “original” string, tokenise it, match each token separately and remove matched ones. When you exhausted all your “original” tokens only then you start highlighting difference on remainder of “original” and “edited”.

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

Sidebar

Related Questions

I basically have a program that filters records from one excel file to another
I want to write an app that will allow a program like iTunes which
Lets say a have program.exe , i will create a python script that will
Basically, I have to write a basic program that solves the n-queen problem, which
I have built a table which is basically done by HorizontalScrollView inside a ScrollView
I basically have 7 select statements that I need to have the results output
I basically have the same question as this guy .. The example in the
I have a program that loads a file (anywhere from 10MB to 5GB) a
Basically, I have a large number of C structs to keep track of, that
i have a program(winform) that runs through a lot of files(in the area of

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.