1
$\begingroup$

Is there a simple way to intersect two strings? I did not find anything about that.

intersect["abcdEfgh","blahcdEzz"] (* "cdE" *) 

By intersection, I mean the longest substring(s) that is(are) common to both strings.

$\endgroup$
5
  • 4
    $\begingroup$ reference.wolfram.com/language/ref/… $\endgroup$ Commented Dec 16, 2017 at 23:31
  • $\begingroup$ @V.E. Perfect. Feel free to write an answer for completeness... $\endgroup$ Commented Dec 16, 2017 at 23:36
  • $\begingroup$ Just one click on V.E.'s hint gives the answer... $\endgroup$ Commented Dec 17, 2017 at 12:34
  • $\begingroup$ @UlrichNeumann Turning the comment into an answer allows me to accept it, and hence remove this question for the unanswered list. $\endgroup$ Commented Dec 17, 2017 at 13:05
  • $\begingroup$ @ anderstood: I got it! $\endgroup$ Commented Dec 17, 2017 at 13:28

1 Answer 1

1
$\begingroup$

As porposed by @V.E. you should use LongestCommonSubsequence[s1,s2]. Example from the documentation:

LongestCommonSubsequence[ "AAABBBBCCCCC", "CCCBBBAAABABA"] (* AAAB *) 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.