STRSORT

Purpose:

Sorts a delimited list of strings.

Syntax:

STRSORT("list", "insep", "outsep", "locale", order, skipblank, type)

"list"

-

A string. The delimited input string.

"insep"

-

Optional. A string, the characters that separate the list into individual substrings. Defaults to the space delimiter.

"outsep"

-

Optional. A string, the characters that separate the output string into individual substrings. Defaults to insep.

"locale"

-

Optional. A string, the locale. Defaults to the system locale.

order

-

Optional. An integer, the sort order.

0:

descending

1:

ascending (default)

skipblank

-

Optional. An integer, ignore blank strings.

0:

include blank strings

1:

ignore blank strings (default)

type

-

Optional. An integer, the type of string sort.

0:

natural (default)

1:

ASCII

Returns:

A string, the sorted output delimited list.

Example:

a = "Tom Dick Sam Sue Tim Ann TIM John"

b = strsort(a)

 

b == "Ann Dick John Sam Sue Tim TIM Tom"

 

The input and output delimiter is a space. The substrings are sorted in ascending order.

Example:

a = "Tom Dick Sam Sue Tim Ann TIM John"

b = strsort(a, 0)

 

b == "Tom TIM Tim Sue Sam John Dick Ann"

 

The input and output delimiter is a space. The substrings are sorted in descending order.

Example:

a = "Tom,Dick,Sam,Sue,Tim,Ann,TIM,John"

b = strsort(a, ",")

 

b == "Ann,Dick,John,Sam,Sue,Tim,TIM,Tom"

 

The input and output delimiter is a comma. The substrings are sorted in ascending order.

Example:

a = "Tom Dick Sam Sue Tim Ann TIM John"

b = strsort(a, " ", ",")

 

b == "Ann,Dick,John,Sam,Sue,Tim,TIM,Tom"

 

The input delimiter is a space and the output delimiter is a comma. The substrings are sorted in ascending order.

Example:

a = "Tom Dick Sam Sue Tim Ann TIM John"

b = strsort(a, " ", " ++ ")

 

b == "Ann ++ Dick ++ John ++ Sam ++ Sue ++ Tim ++ TIM ++ Tom"

 

The input delimiter is a space and the output delimiter is a space followed by two plus signs followed by a space. The substrings are sorted in ascending order.

Example:

a = ",,,a5,a2,,a1,a3"

b = strsort(a, ",", 1, 1)

 

b == "a1,a2,a3,a5"

 

Blank substrings are ignored.

Example:

a = ",,,a5,a2,,a1,a3"

b = strsort(a, ",", 1, 0)

 

b == ",,,,a1,a2,a3,a5"

 

Blank substrings are not ignored.

Example:

a = "str3,str100,str10,str02,str1"

b = strsort(a, ",", 1, 1, 0)

 

b == "str1,str02,str3,str10,str100"

 

The string is sorted in natural ascending order (the default).

Example:

a = "str3,str100,str10,str02,str1"

b = strsort(a, ",", 1, 1, 1)

 

b == "str02,str1,str10,str100,str3"

 

The string is sorted in ASCII ascending order.

Example:

a = "Birnen Äpfel Ungetüme Apfel Ungetiere Österreich";

b = strsort(a, " ", " ")

 

b == "Apfel Äpfel Birnen Österreich Ungetiere Ungetüme"

 

The string is sorted in natural ascending dictionary order (the default).

Example:

a = "Birnen Äpfel Ungetüme Apfel Ungetiere Österreich";

b = strsort(a, " ", " ", "de-DE-u-co-dict")

 

b == "Apfel Äpfel Birnen Österreich Ungetiere Ungetüme"

 

Same as above, except dictionary sorting order is explicitly specified with the "de-DE-u-co-dict" locale.

Example:

a = "Birnen Äpfel Ungetüme Apfel Ungetiere Österreich";

b = strsort(a, " ", " ", "de-DE-u-co-phonebk")

 

b == "Äpfel Apfel Birnen Österreich Ungetiere Ungetüme"

 

The string is sorted in ascending German phonebook order. Äpfel is evaluated internally as Aepfel. Because the second character e precedes p in the alphabet, Äpfel naturally sorts before Apfel.

Remarks:

If no substrings are found, the input string is returned.

 

The input and output delimiters can contain multiple characters.

 

Natural order sorts strings with embedded digits based on the numeric value of the digits. ASCII order sorts strings based on the ASCII numeric value of each character.

 

The locale option conforms to the BCP-47 language tag convention. For example, "de-DE" and "de-DE-u-co-dict" sort German text in dictionary order, whereas "de-DE-u-co-phonebk" sorts German text in phone book order.

See Also:

DTSORT

SORT

SORTROWS

STRCAT

STRCMP

STREXTRACT

STRFIND

STRGET

STRIDXGET

STRLIST

STRMATCH

STRREPLACE