Function Repository Resource:

StringSort

Source Notebook

Sort the characters in a string

Contributed by: Arnoud Buzing

ResourceFunction["StringSort"]["string"]

sorts the characters in "string" into canonical order.

Details and Options

Strings are ordered as in a dictionary, with uppercase versions of letters coming after lowercase ones. Ordinary letters are placed first, followed in order by script, Gothic, doublestruck, Greek and Hebrew. Mathematical operators appear in order of decreasing precedence

Examples

Basic Examples (4) 

Sort characters in a string:

In[1]:=
ResourceFunction["StringSort"]["Hello world"]
Out[1]=

Sort fifty random characters:

In[2]:=
randstr = FromCharacterCode[RandomInteger[255, 50]]
Out[2]=
In[3]:=
ResourceFunction["StringSort"][randstr]
Out[3]=

Sort a mathematical string:

In[4]:=
ResourceFunction["StringSort"][ToString[a^2 + b^2 == c^2, InputForm]]
Out[4]=

Sort the first characters from different character sets:

In[5]:=
ResourceFunction[
 "StringSort"]["abc\[Alpha]\[Beta]\[Chi]ABC\[FormalA]\[FormalB]\[FormalC]"]
Out[5]=

Scope (1) 

Sort all the characters in Hamlet:

In[6]:=
Short[ResourceFunction["StringSort"][ResourceData["Hamlet"]], 4]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 October 2018

License Information