And as I think about it you need to deal with the multiple match issue
better:

$bestMatch:=""

$bestMatch_n_words:=0


Then you loop through the shorter array:

$start:=1  //  first search is on the first word of <longer array>

For($i;1;size of array(<shorter array>))

$pos1:=Find in array(<longer array>;<shorter array>{$i}; $start)

while($pos1>0)   // this word matches

$start:=$pos1+1  //  the next Find in array for this word starts on the
next word

$thisMatch:=<shorter array>{$i} // a string of matches

$n_words:=1

// now you need to loop through the remaining words in <shorter array>
until you stop matching

$j:=$i+1 //        the word in <shorter array> to check next

$k:=$pos1+1 // the word in <longer array> that must match <shorter array>

// we need to make sure we don't overrun the size of either array

if ( $j< size of array(<shorter array>)) & ( $k< size of array(<longer
array>))

while (<longer array>{$k} = <shorter array>{$j})

$thisMatch:=$thisMatch+" "+<shorter array>{$j}

$n_words:=$n_words+1

end while


if($n_words>$bestMatch_n_words)

$bestMatch_n_words:=$n_words

$bestMatch:=$thisMatch

end if

end if

end while

$start:=1  //  moving on to next word of <shorter array>

End for

I probably should have actually coded this...

On Thu, Aug 22, 2019 at 9:42 PM Kirk Brooks <[email protected]> wrote:

> Damn, hit send too soon.
> I think you split the two strings into arrays.
> You create:
>
> $bestMatch:=""
>
> $bestMatch_n_words:=0
>
> Then you loop through the shorter array:
>
> For($i;1;size of array(<shorter array>))
>
> $pos1:=Find in array(<longer array>;<shorter array>{$i})
>
> if($pos1>-1) // this word matches
>
> $thisMatch:=<shorter array>{$i} // a string of matches
>
> $n_words:=1
>
> // now you need to loop through the remaining words in <shorter array>
> until you stop matching
>
> $j:=$i+1 //        the word in <shorter array> to check next
>
> $k:=$pos1+1 // the word in <longer array> that must match <shorter array>
>
> while (<longer array>{$k} = <shorter array>{$j}) & ( $j< size of
> array(<shorter array>))
>
> $thisMatch:=$thisMatch+" "+<shorter array>{$j}
>
> $n_words:=$n_words+1
>
> end while
>
>
> if($n_words>$bestMatch_n_words)
>
> $bestMatch_n_words:=$n_words
>
> $bestMatch:=$thisMatch
>
> end if
>
> end if
>
> End for
>
> Use Split string if you can use collections and it should be pretty darn
> fast. Also need to decide what to do with matches of equal length.
>
> On Thu, Aug 22, 2019 at 9:35 PM Kirk Brooks <[email protected]> wrote:
>
>> Chip,
>> I think you split the two strings into arrays.
>> You create two more arrays: $aMatches,  and $aNumWords (unless by
>> 'length' you mean number of characters)
>>
>> The you look through the shorter array:
>>
>> For($i;1;size of array(<shorter array>)
>>
>> $pos1:=Find in array(<longer array>;$<shorter array>{$i})
>>
>> if($pos1>-1) // this word matches
>>
>> $thisMatch:=<shorter array>{$i} // a string of matches
>>
>> $n_words:=1
>>
>> // now you need to loop through the remaining words in <shorter array>
>> until you stop matching
>>
>> $j:=$i+1 //        the word in <shorter array> to check next
>>
>> $k:=$pos1+1 // the word in <longer array> that must match <shorter array>
>>
>> while (<longer array>{$k} = <shorter array>{$j}) & ( $j< size of
>> array(<shorter array>))
>>
>> $thisMatch:=$thisMatch+" "+<shorter array>{$j}
>>
>> $n_words:=$n_words+1
>>
>> end while
>>
>>
>> end if
>>
>> End for
>>
>>
>> On Thu, Aug 22, 2019 at 1:13 PM Chip Scheide via 4D_Tech <
>> [email protected]> 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]
>>> **********************************************************************
>>
>>
>>
>> --
>> Kirk Brooks
>> San Francisco, CA
>> =======================
>>
>> What can be said, can be said clearly,
>> and what you can’t say, you should shut up about
>>
>> *Wittgenstein and the Computer *
>>
>>
>
> --
> Kirk Brooks
> San Francisco, CA
> =======================
>
> What can be said, can be said clearly,
> and what you can’t say, you should shut up about
>
> *Wittgenstein and the Computer *
>
>

-- 
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
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]
**********************************************************************

Reply via email to