Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object >

Clib.qsort() Method


This method sorts elements in an array.

Syntax

Clib.qsort(array, [elementCount, ]compareFunction)

Parameter
Description
array
An array to sort
elementCount
The number of elements in the array, up to 65,536
compareFunction
A user-defined function that can affect the sort order

Returns

Not applicable

Usage

This method sorts elements in an array, starting from index 0 to elementCount-1. If elementCount is not supplied, the method sorts the entire array. This method differs from the Array.sort() method in that it can sort dynamically created arrays, whereas Array.sort() works only with arrays explicitly created with a new Array statement.

Example

The following example prints a list of colors sorted in reverse alphabetical order, ignoring case:

// initialize an array of colors
var colors = { "yellow", "Blue", "GREEN", "purple", "RED",
"BLACK", "white", "orange" };
// sort the list using qsort and our ColorSorter routine
Clib.qsort(colors,"ReverseColorSorter");
// display the sorted colors
for ( var i = 0; i <= getArrayLength(colors); i++ )
   Clib.puts(colors[i]);

function ReverseColorSorter(color1, color2)
// do a simple case insensitive string
// comparison, and reverse the results too
{
   var CompareResult = Clib.stricmp(color1,color2)
   return( _CompareResult );
}

The output of the preceding code would be:

yellow
white
RED
purple
orange
GREEN
Blue
BLACK

See Also

sort() Method


 Siebel eScript Language Reference 
 Published: 18 April 2003