0

I am using google's diff-match-patch in java for finding differences in two strings.

String s1 = "Comment, Version, Message Type, Action, USI prefix, USI Value, Primary Asset";
String s2 = "Comment, Version, Message Type, Action, USI prefix, JPY Value, Primary Asset, Secondary Asset";

DiffMatchPatch dmp = new DiffMatchPatch();
LinkedList<DiffMatchPatch.Diff> diff = dmp.diffMain(s1, s2, false);

System.out.print(diff);

The code is giving correct output:

[Diff(EQUAL, "Comment, Version, Message Type, Action, USI prefix,"), 
 Diff(DELETE, "USI"),
 Diff(INSERT, "JPY"),
 Diff(EQUAL, "Value, Primary Asset"),
 Diff(INSERT, ", Secondary Asset")]

How to know that at which index the change has occured? E.g. there are two "USI" in the string, how to know that which "USI" is modified? I need the index numbers at which the change occured.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
ritik jain
  • 540
  • 1
  • 5
  • 13

0 Answers0