0

I would like to highlight and report out text differences between 2 Strings with Java . What is a good way to do this? Do I need to tokenize both Strings and do a compare or is there an easier way?

Example:

I have 2 Strings like so:

Previous String : CLIMB TO 5900' then climbing RIGHT turn to 11000' on heading 193 and outbound Current String : CLIMB TO 6500' then climbing LEFT turn to 11000'on heading 201 and inbound

I am currently just displaying the previous and current strings by doing a String compare, but what i want is to highlight the actual substring that did change from the previous string, like so:

Current String : CLIMB TO 6500' then climbing LEFT turn to 11000'on heading 201 and inbound

Appreciate your help!

Thank you praveen

praveen
  • 47
  • 2
  • 7
  • 1
    Check this out http://stackoverflow.com/questions/15303631/what-are-some-algorithms-for-comparing-how-similar-two-strings-are – madmik3 Nov 26 '14 at 05:43

1 Answers1

-1

Yes , you can possibly tokenize the string characters . Use charAt(int index) to tokenize the string characters. You can see the example code below : -

for(int i=0 ; i<stringNameOrg.length ; i++)
{
   if(stringNameOrg.charAt(i) != stringNameNew.charAt(i))) //considering both strings are of same size
   {
      //do stuff
   }
}