strsort(X;Y;U;D)

Returns the characters, or the elements delimited by a particular value, of a given string sorted in ascending or descending order.

Syntax

strsort(X;Y;U;D)
bstrsort(X;Y;U;D)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y text The character or string to be used as the delimiter in X

A scalar value or the name of a column

U integer Specifies whether to only include unique values in the result

If U=0, all elements (including duplicate values) that are found in X are included in the result.

If U=1, only unique elements in X are included in the result (i.e., duplicate elements are removed).

If U is non-zero (including N/A) it is treated as if it were 1.

D integer Specifies the order of the sort

If D=1, the elements are sorted in ascending order.

If D=-1, the elements are sorted in descending order.

If D is N/A, it is treated as if it were -1.

Return Value

If Y is empty, this function returns the text value corresponding to the characters of X in sorted order. If D=1, the characters are sorted in ascending order; if D=-1, the characters are sorted in descending order. If U=0, all characters are returned; otherwise, only one of each character appears in the result.

If Y is non-empty, then it splits X using Y as a delimiter and returns a delimited list of the elements sorted up or down according to D. Again, duplicate elements are removed if U is not 0.

If X is N/A, then the result is N/A.

If Y is N/A, then the characters of X are sorted.

Sample Usage

value string2 unique order strsort(value;string2;unique;order)
'apple' '' 0 1 'aelpp'
'apple' '' 1 -1 'plea'
'apple,pear,cherimoya' ',' 0 -1 'pear,cherimoya,apple'
'apple--pear--apple--peach--pear--banana' '--' 1 1 'apple--banana--peach--pear'

Additional Information

  • strsort is Unicode (UTF-8) compliant and will work with Unicode or plain ASCII text fields.
  • If passed a string argument that is not legal Unicode, it will by default signal an error (configurable as a user preference).
  • A corresponding function bstrsort can be used with non-Unicode strings (e.g., binary or legacy encodings).
  • Unicode code-point order (which does not correspond to the lexicographic order used in any particular language) is used for sorting.