Wolfram Computation Meets Knowledge

StringSort

Contributed by: Arnoud Buzing

Sort the characters in a string

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, double‐struck, Greek, and Hebrew. Mathematical operators appear in order of decreasing precedence

Examples

Basic Examples

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

Sort all the characters in Hamlet:

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

Resource History