Wolfram Research

Function Repository Resource:

StringDisjointQ

Source Notebook

Test if two strings have no common characters

Contributed by: Arnoud Buzing

ResourceFunction["StringDisjointQ"][s1,s2]

yields True if s1 and s2 do not share any common characters and False otherwise.

Examples

Basic Examples

Check whether two strings are disjoint:

In[1]:=
ResourceFunction["StringDisjointQ"]["Hello", "World"]
Out[1]=
In[2]:=
ResourceFunction["StringDisjointQ"]["Hello", "Miami!"]
Out[2]=

Scope

All characters are supported:

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

Applications

See if two words are disjoint in two languages that share an alphabet:

In[5]:=
AssociationMap[
 ResourceFunction["StringDisjointQ"][#, First[WordTranslation[#, "Spanish"]]] &,
 {"mother", "infant", "truck", "piano", "happy"}]
Out[5]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information