Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert a list of strings into a phrase
ResourceFunction["PhraseRiffle"][{s1,s2,s3,…}] creates a phrase by concatenating all the si using English separators. | |
ResourceFunction["PhraseRiffle"][{s1,s2,s3,…},fsep] uses fsep as a custom final separator string. | |
ResourceFunction["PhraseRiffle"][{s1,s2,s3,…},fsep,sep] uses sep as a custom separator and fsep for the final pair only. | |
ResourceFunction["PhraseRiffle"][fsep][{s1,s2,s3,…}] operator form with custom final separator fsep. | |
ResourceFunction["PhraseRiffle"][fsep,sep][{s1,s2,s3,…}] operator form with custom final and common separators. |
Convert a list of strings into a phrase in English:
In[1]:= | ![]() |
Out[1]= | ![]() |
For other languages, use a different final separator:
In[2]:= | ![]() |
Out[2]= | ![]() |
The main separator is also customizable:
In[3]:= | ![]() |
Out[3]= | ![]() |
An operator form is supported:
In[4]:= | ![]() |
Out[4]= | ![]() |
If the list of strings is empty, the result is an empty string:
In[5]:= | ![]() |
Out[5]= | ![]() |
If there is single string in the list, it is returned unchanged:
In[6]:= | ![]() |
Out[6]= | ![]() |
Create an operator form with a custom separator:
In[7]:= | ![]() |
Out[7]= | ![]() |
Use it on a list:
In[8]:= | ![]() |
Out[8]= | ![]() |
Include a serial comma:
In[9]:= | ![]() |
Out[9]= | ![]() |
Make a phrase stating the planets in the solar system:
In[10]:= | ![]() |
Out[10]= | ![]() |
PhraseRiffle is similar to the StringRiffle function but with the ability to customize the last separator. It is in fact implemented as two StringRiffle operations:
In[11]:= | ![]() |
Out[11]= | ![]() |
In[12]:= | ![]() |
Out[12]= | ![]() |
Spaces around your custom separator are not added automatically:
In[13]:= | ![]() |
Out[13]= | ![]() |
Add the spaces for the correct result:
In[14]:= | ![]() |
Out[14]= | ![]() |
Count up to ten:
In[15]:= | ![]() |
Out[15]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License