# Finding the longest common substrings between two strings

Hello!

I am looking for a way in EasyMorph to do the following: for two strings, I would like to obtain the 5 longest common substrings.

I have found an algorithm online that prints the longest common substring between two strings: https://www.geeksforgeeks.org/print-longest-common-substring/ (the code is available in different programming languages). If this code can be run by EasyMorph (this is where the Powershell action comes in, right?), I was thinking of the following:

• For each pair of strings, the following process is followed:

1. Run the algorithm to find the longest common substring of the two strings
2. Once the longest common substring has been found:
1. Store it
2. Replace this longest common substring for ‘’ in each of the compared strings (so basically, erase it from both strings).
3. Once erased from both strings, run the algorithm again to find the next longest matching substring in the modified strings. Do this process 4 times so that we obtain the 5 longest substrings in each pair of strings.
• Once this is finished, continue the iteration with the next pair of strings, for which the 5 longest common substrings are found.

In the case there are two (or more) longest substrings of the same length, the process should get the first one, and then in the next repetition this first substring will no longer be there (as it has been erased), so the other longest substring will be extracted.

So here would be an example:

String1 = ‘This is an example of a text.’
String2 = ‘This is another example of a text.’

1. Algorithm runs
2. Returns ’ example of a text.’
1. Keep ’ example of a text.’ in another table
2. Replace ’ example of a text.’ in both strings for ‘’, so now String1 = ‘This is an’ and String 2= ‘This is another’
3. Run the algorithm again with these two new strings, and we get the substring ‘This is an’, and store this substring in another table. If we replace ‘This is an’ is both substrings, String1 =’’ and String 2=‘other’. So in this case the third, fourth and fifth longest substrings (for this pair of strings) will be blank.)
• Once this is finished for String1 and String2, continue the iteration with the next pair of strings, for which the 5 longest common substrings are found.

Do you think the code provided in the link before can be run in EasyMorph through Powershell or other means? Does the whole process seem logical?

Thanks very much!

Roberto