STRSORT

Purpose:

Sorts a delimited list of strings.

Syntax:

STRSORT("list", "insep", "outsep", 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.

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.

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.

See Also:

SORT

STRCAT

STRCMP

STREXTRACT

STRFIND

STRGET

STRLIST

STRMATCH

STRREPLACE