CValueSet:SortKey


The SortKey method lists the contents of the CValueSet as (string key, value) pairs by sorting on the string key.

Syntax

CValueSet:SortKey()

Remarks

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 key F" sorts to a lower set index than "my key 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 sorts its members by the string keys:

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:SortKey()

-- sort set members by their string key

S:List("After sort:")

 

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

Before SortKey:

key_9      -1.4

key_2      107.23

key_3      78.6

 

After SortKey:

key_2      107.23

key_3      78.6

key_9      -1.4

Related Topics

CValueSet Class, Add, List, Sort


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