Function Repository Resource:

StringIntersectingQ

Source Notebook

Test if two strings have any common characters

Contributed by: Arnoud Buzing

ResourceFunction["StringIntersectingQ"][s1,s2]

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

Examples

Basic Examples (1) 

Check whether two strings have any intersecting characters:

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

Scope (1) 

All characters are supported:

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

Applications (1) 

See if some English words intersect their Spanish translations:

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

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 October 2018

License Information