Thursday, May 7, 2015

How do i compare two strings and get the difference?

I have explained with an example of what exactly I' am looking for in my previous post. s1, s2 are the two strings to be compared and strDiff is the desired result. How is that not clear? 

I'm comparing INI file key:value pairs. So most of the time the string will be different by just one or two charecters. I want to get the difference in the two strings.

Your two examples don't, for example, show what should happen in either of the two examples that I gave.

Are you trying to delete from s1 every character that occurs in s2? If so does the order of the characters matter? What if a character occurs twice in s1 but only once in s2?

Or do you mean you want to first check that s2 is a substring of s1 (and presumably throw an exception if it is not) and then remove the s2 substring from s1?

I could guess other things from your two examples, that is why I'm asking you to explain what you want.

No comments:

Post a Comment