Function Repository Resource:

StringFunction

Use functions meant for lists on strings

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["StringFunction"][f][string,…] applies f to the characters in string.

Details and Options

The function f should return a string or a list of strings when given a list of characters.
If f returns a list, the output is joined into a single string.
ResourceFunction["StringFunction"][f] is automatically threaded over lists, as if it had the Listable attribute.

Examples

Basic Examples (7)

Use a function meant for lists on a string:

 In[1]:=
 Out[1]=

Create new string functions from existing functions:

 In[2]:=
 Out[2]=
 In[3]:=
 Out[3]=

Rotate a string:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

Get a random permutation of a string:

 In[6]:=
 Out[6]=

Replace all vowels:

 In[7]:=
 Out[7]=

Insert spaces between each letter:

 In[8]:=
 Out[8]=

More examples for StringFunction:

 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

Scope (4)

Functions created by StringFunction behave as though they were Listable:

 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=

This is similar to many of the built-in string functions:

 In[19]:=
 Out[19]=

Use a custom function in StringFunction:

 In[20]:=
 Out[18]=
 In[21]:=
 Out[21]=

If the given function produces nested lists of strings, the list structure will be preserved:

 In[22]:=
 Out[22]=

Characters are separated using Characters instead of byte values, so encoding is preserved:

 In[23]:=
 Out[23]=

Properties and Relations (2)

The given function is applied to a list of strings:

 In[24]:=
 Out[24]=
 In[25]:=
 Out[25]=

StringFunction applies f to Characters["string"] and joins the result:

 In[26]:=
 Out[26]=
 In[27]:=
 Out[27]=

Possible Issues (2)

The given f must produce a string or lists of strings from its output:

 In[28]:=
 Out[28]=
 In[29]:=
 Out[29]=

Validity is not determined until evaluation of StringFunction[][args]:

 In[30]:=
 Out[30]=
 In[31]:=
 Out[31]=

Neat Examples (1)

Create a scrolling marquee to experience that ‘90s website nostalgia:

 In[32]:=
 In[33]:=
 Out[33]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

• 1.0.0 – 08 February 2019