DADiSP Worksheet Functions > Function Categories > String Manipulation > STRSORT
Sorts a delimited list of strings.
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.
|
||||
skipblank |
- |
Optional. An integer, ignore blank strings.
|
||||
type |
- |
Optional. An integer, the type of string sort.
|
A string, the sorted output delimited list.
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.
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.
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.
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.
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.
a = ",,,a5,a2,,a1,a3"
b = strsort(a, ",", 1, 1)
b == "a1,a2,a3,a5"
Blank substrings are ignored.
a = ",,,a5,a2,,a1,a3"
b = strsort(a, ",", 1, 0)
b == ",,,,a1,a2,a3,a5"
Blank substrings are not ignored.
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).
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.
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.