Wolfram Computation Meets Knowledge

StringIntersection

Contributed by: Arnoud Buzing

Find the characters common to multiple strings

ResourceFunction["StringIntersection"][s1,s2,]

gives a string containing the characters common to all the si.

Details and Options

Characters in the returned string are sorted in standard order.

Examples

Basic Examples

Find characters in one string that are also another:

In[1]:=
ResourceFunction["StringIntersection"]["Hello", "World"]
Out[1]=

Scope

Use several strings:

In[2]:=
ResourceFunction[
 "StringIntersection"]["Which of the characters are common?", "Some \
of these", "And some of these", "Don't forget these"]
Out[2]=

All characters are supported:

In[3]:=
{str1, str2} = TextCases[ResourceData["The Odyssey - Greek"], "Sentence"][[1 ;; 2]]
Out[3]=
In[4]:=
ResourceFunction["StringIntersection"][str1, str2]
Out[4]=

Resource History