1

I am wondering if there's an easy way to detect "phrases" in two strings without it being in quotes. For example:

"i like jack in the box" and "jack in the box has good food"

In this case, "jack in the box" would be detected. Now I could potentially go through the whole first string, see if it's in the second string, which it's not... and keep cutting down to a smaller length and running it through the second string until I find the 3-word-match of "jack in the box"... but it's not too efficient.

Any help would be great -- thanks!

ewindsor
  • 885
  • 10
  • 24
  • Take a look at the wiki page: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem – Trevor Jun 29 '12 at 18:09

1 Answers1

2

You are referring to the Longest Common Subsequence problem. This is used as the basis of a string comparison.

There are many SO questions relating to this problem: https://stackoverflow.com/search?q=longest+common+subsequence

The algorithm isn't too hard to implement. Wikipedia has pseudocode that you can use as a starting point.

Community
  • 1
  • 1
Seth Flowers
  • 8,990
  • 2
  • 29
  • 42