CValueSet:Sort


The Sort method sorts the contents of the CValueSet according to its values.

Syntax

CValueSet:Sort()

Remarks

When the set has type "string", the sorting results may be confusing because string sorting uses standard rules based on the decimal values of the ASCII character set. For example, "my value F" sorts to a lower set index than "my value c". This happens because the "F" character has ASCII decimal value 70 whereas "c" has ASCII decimal value 99. For details, see the ASCII character set on the Web.

Example

The following example creates a CValueSet S and then sorts its members by value:

S = new_valueset("number")

-- constructor, set to values of type "number"

S:Add( "key_1", 158.25 )

-- add a key and value at index 1

S:Add( "key_2", -7.23 )

-- add a key and value at index 2

S:Add( "key_3", 78.6 )

-- add a key and value at index 3

S:List("Before sort:")

 

S:Sort()

-- sort set members by value

S:List("After sort:")

 

Below is the result of the previous script as listed in a CTextView window:

Before Sort:

key_1      158.25

key_2      -7.23

key_3      78.6

 

After Sort:

key_2      -7.23

key_3      78.6

key_1      158.2

Related Topics

CValueSet Class, Add, List, GetType, SortKey


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.