0

Lets say that I have two strings:

  1. "The System is in halt state."

  2. "The System is in [A] state."

Is it possible to find the difference between the two strings ,I need both [A] and halt as output.

As of now i'm splitting every word and check for the match.

Is there any better way...?

1
  • Similar question (and answer) can be found here
    – JleruOHeP
    Mar 30, 2012 at 5:30

3 Answers 3

1

string a = "The System is in halt state."; string b = "The System is in [A] state.";

        var vardiff =( a.Split(new char[] { ' ' }).Except(b.Split(new char[] { ' ' }))).ToList<string>();
        var vardiff1 = (b.Split(new char[] { ' ' }).Except(a.Split(new char[] { ' ' }))).ToList<string>();
1
  • will it not fail if the 2nd line is "The System is in [A] Marina state." ?
    – Dhananjay
    Mar 30, 2012 at 6:31
0

Check this out:Diff Algorithm

Also: Longest common subsequence

There is also an implementation described here: sample code

1
  • ganeeesh. pathutaen da,, i have used Longest common sub sequence logic dhan da.. Is there any Regular Expression ?..
    – gout
    Mar 30, 2012 at 5:38
0

Really, the question isn't entirely clear on what you mean by "difference". Is it simply the number of characters that are the same, or a more heuristic way of comparing unmatched strings?

One algorithm you might want to explore is the Approximate String Comparisons Using Levenshtein Distance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.