1

I have two different strings, result and result1. result is a new value obtained from a website content without changing anything in website and it is stored in SQLite and later the website content will be changed and obtain the content and it will be saved in result1. I want to compare these two string result and result1 and find out which content is added newly. I want to show the new added content. Here I mentioned the code to check the result and result1 values.

String[] items = result1.split(">");
for (String item : items)
{
    Log.i("Result1", item);
}
KOUSIK daniel
  • 305
  • 1
  • 3
  • 11

2 Answers2

1

This is a clear case of the Levenshtein distance. Check it out and google will provide you with lots of implementations ;)

Roel Strolenberg
  • 2,922
  • 1
  • 15
  • 29
  • Does that tell you which is different? As far as I know it only tells you, that something is different. – Tom Jun 22 '15 at 14:51
  • It tells you how different two strings are. So if the difference > 0, you know it's different. And what do you mean by 'which is different'? Can you compare an apple to an orange and say: 'the orange is different from the apple' without implying the apple is also different from the orange? If string A and B are different, then both are different. – Roel Strolenberg Jun 22 '15 at 14:55
  • Yes, there are ways to tell the difference: http://stackoverflow.com/questions/18344721/extract-the-difference-between-two-strings-in-java – Tom Jun 22 '15 at 15:01
  • Ahh now I understand your question, that way you know what the difference is! But those operations are quite compilation-time heavy. So if you only need to know IF there is a difference, use levenshtein, otherwise use google's tools. – Roel Strolenberg Jun 22 '15 at 15:06
0

Difference between 2 String can be found using

String strDiffChop(String s1, String s2) {
    if (s1.length > s2.length) {
        return s1.substring(s2.length - 1);
    } else if (s2.length > s1.length) {
        return s2.substring(s1.length - 1);
    } else {
        return null;
    }
}

I don't own this , but have tried .

Find difference between two StringsSee this

Community
  • 1
  • 1
Prabhuraj
  • 928
  • 2
  • 8
  • 14