Thanks I'll look at it tomorrow
On Thu, 22 Aug 2019 16:14:49 -0500, Matt Wennerlund wrote: > If it doesn't need to work on full word boundaries, then the code > below works. For the two below, the common match would be " have > fleas". 21 lines of 4d code, no regex magic, unfortunately. A few > more lines of code if you needed to ignore starting and ending spaces > of found matches. > > $string1:="This is my dog, it may have fleas" > $string2:="My dog does not have fleas" > > > There are probably ways to speed it up. $maxlengthstring_t should > end up with the longest string. > > $maxlengthstring_t:="" > $string1:="This is my dog, it may have fleas" > $string2:="My dog does not have fleas" > $lengthtocheck_i:=Length($string1) > For ($k;1;Length($string1)) //This is my dog; his is my dog; is is my dog... > $stringtotest_t:=Substring($string1;$k) > $lengthtocheck_i:=Length($stringtotest_t) > For ($startPosition_i;1;Length($stringtotest_t)) //"This is my > dog"; "This is my do"; "This is my d"... > > $testsubstring:=Substring($stringtotest_t;$startPosition_i;$lengthtocheck_i) > $found_i:=Position($testsubstring;$string2) > If ($found_i>0) > If (Length($testsubstring)>Length($maxlengthstring_t)) > $maxlengthstring_t:=$testsubstring > $startPosition_i:=100000000 > End if > Else > $startPosition_i:=100000000 > End if > $lengthtocheck_i:=$lengthtocheck_i-1 > End for > End for > > > Matt Wennerlund > > > > Chip Scheide via 4D_Tech wrote: >> Given 2 strings, >> I want to find, and return, the longest substring which is the same in >> both, regardless where in either string the longest substring starts. >> >> ex: >> 1- This is my dog >> 2- My dog does not have fleas >> longest common string is 'my dog' >> >> how to go about this, efficiently? >> I am assuming that there is regex black magic that would do this. >> >> --------------- >> Gas is for washing parts >> Alcohol is for drinkin' >> Nitromethane is for racing >> ********************************************************************** >> 4D Internet Users Group (4D iNUG) >> Archive: http://lists.4d.com/archives.html >> Options: https://lists.4d.com/mailman/options/4d_tech >> Unsub: mailto:[email protected] >> ********************************************************************** > > --------------- Gas is for washing parts Alcohol is for drinkin' Nitromethane is for racing ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

