Xbasic

SORTSUBSTR Function

Syntax

Output_String as C = SORTSUBSTR(C string,C delimiter[,C Direction][,C Token type])

Arguments

string

A delimited string of character values.

delimiter

Any character.

Direction

Optional. Default = "A"; "A" = Ascending."D" = Descending

Token

Optional. Default = "C"; "C" = Character data. "N" = Numeric data. "X" = Sorts on length of data

Description

Returns a string of sorted tokens from a character string - token type 'N'-numeric 'X'-length.

Discussion

SORTSUBSTR() sorts a delimited string of values and returns the result in a string called Output_String. Direction is case sensitive.

Example

These examples sort "words" in a string. Note that a "word" can be defined by any delimiter.

dim string as C
dim sorted as C
dim numberstring as C
dim sortednumbers as C
string = "cde, abc, xyz, aad, gef"
sorted = sortsubstr(string, ",", "A", "C")
numberstring = "12, 23, 123, 45, 456, 16, 56"
sortednumbers = sortsubstr(numberstring, ",", "A", "N")
? sortsubstr("X,xx,xxxxxxx,xxx,xxxx,iiiii", ",", "A", "X")
= "X,xx,xxx,xxxx,iiiii,xxxxxxx"

This example sorts lines in a string.

dim list as C
list = 
beta
gamma
alpha
delta
%str%
? list
= beta
gamma
alpha
delta
? sortsubstr(list, crlf() )
= alpha
beta
delta
gamma

See Also