Wolfram Research

Function Repository Resource:

StringIntersection

Source Notebook

Find the characters common to multiple strings

Contributed by: Arnoud Buzing

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 in 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]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information