ARRAY SORT

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > Array functions >

ARRAY SORT

 

Description

 

Sort an array or part of the array.

 

Syntax

 

ARRAY SORT ArrayVariable([StartIndex]) [FOR nElements] [, COLLATE UCASE] [, {ASCEND | DESCEND}] [, ASFILES]

 

Returns

 

None

 

Parameters

 

Name

Type

Optional

Meaning

ArrayVariable


No

Name of a declared and already dimensioned array.

StartIndex

Number

Yes

The element index inside the array from which to start. If omitted, 1 is assumed

nElements

Number

Yes

Number of elements to sort starting from StartIndex. If omitted, end of the array is assumed.

 

Remarks

 

ASFILES is a special clause used to sort kind of file names string using the so called "natural sorting" comparison.

This clause can be used when sorting files whose names contains a sort of patter composed by name + number + extension. Each Array element is decomposed in the single part of the patter (Name, Number, Extension) and adapted to be sorted.

No modifications will take place to the original array elements.

 

Example:

Picture1.jpg

Picture2.jpg

Picture3.jpg

Picture4.jpg

Picture5.jpg

Picture6.jpg

Picture7.jpg

Picture8.jpg

Picture9.jpg

Picture10.jpg

Picture11.jpg

Picture12.jpg

 

A standard order would sort the above list in the following way

While using ASFILES it will sort considering the numeric part be a number

Picture1.jpg

Picture10.jpg

Picture11.jpg

Picture12.jpg

Picture2.jpg

Picture3.jpg

Picture4.jpg

Picture5.jpg

Picture6.jpg

Picture7.jpg

Picture8.jpg

Picture9.jpg

Picture1.jpg

Picture2.jpg

Picture3.jpg

Picture4.jpg

Picture5.jpg

Picture6.jpg

Picture7.jpg

Picture8.jpg

Picture9.jpg

Picture10.jpg

Picture11.jpg

Picture12.jpg

 

ASFILES also compares string length for optimum comparison.

 

Restrictions

 

ASFILES clause can sort strings up to 255 chars maximum file lenght

 

See also

 

LBound, UBound, ARRAY ASSIGN,

 

Examples