# Comparing & Finding changes

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, on paper my problem is easy to fix, but in reality i have only little idea about how to do this. So this is what i have
string olddata = "100,354,999,123,555";
string newdata = "100,200,123,234";
any ideas about how to find out which values are deleted and which are added? i expect to see something like this as result:
string added = "200,234";
string removed = "354,999,555";
Any help would be appreciated :) p.s. im using c#

##### Share on other sites
I don't know c#, but I imagine the general procedure would be:

1)Convert the old and new lists of numbers from one long string into tokens. There are probably library functions for this.

2)Convert those tokens into integers. I'm sure there's some type of container like a vector in c#, so use that to store the tokens in.

3)Sort the containers

for your example you would have something like this right now:
oldNumbers newNumbers  100        100  123        123  354        200  555        234  999

4)Create two indices, one for each container

5)Create two new containers to store the added and removed data. You can probably just go directly from integers to strings here

6)Compare the values from above for each case:
a)if both numbers are equal, incrememnt both indices
b)if oldNumbers > newNumbers add the number from newNumbers into the 'added numbers' container. Then increment the index for newNumbers
c)if oldNumbers < newNumbers add the number from oldNumbers into the 'removed numbers' container. Then increment the index for oldNumbers
d)if one container is empty, just output the non-empty container into the appropriate add or remove container

I think that will do it. Hopefully I didn't leave out any steps.

EDIT: case D is important too!

##### Share on other sites
First, I assume that you are able to split your strings into individual strings that represent your numbers. Then the algorithm is rather simple:
olddatacpy = olddatafor each number N in newdata  if N is in olddatacpy {    remove N from olddatacpy  } else {    add N to added  }}removed = olddatacpy

If you need a more general diff algorithm, it will be trickier :)

HTH,

##### Share on other sites
Finally, Got it!

Thanks, for the help! :D

• 17
• 10
• 19
• 14
• 19