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...?

gout
  • 802
  • 10
  • 32
  • Similar question (and answer) can be found [here](http://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings) – JleruOHeP Mar 30 '12 at 05:30

3 Answers3

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>();
Vetrivel mp
  • 1,214
  • 1
  • 14
  • 29
0

Check this out:Diff Algorithm

Also: Longest common subsequence

There is also an implementation described here: sample code

ganesshkumar
  • 1,317
  • 1
  • 16
  • 35
  • ganeeesh. pathutaen da,, i have used Longest common sub sequence logic dhan da.. Is there any Regular Expression ?.. – gout Mar 30 '12 at 05: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.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466