StringSort Class Reference
This is a convenience class that provides generic sorting class for
ActiveScript-compatible languages. It is a non-trivial
task to sort data in scripting, especially in VBScript where there is
no equivalent for the JScript sort
function. It is
designed as a
list of strings. Each string in the list is a key based on which the
sort is done. Each key can have an optional integer value that can be
used, for example, to retrieve a record in an array.
To create a StringSort object, use CreateObject("MetadataLib.StringSort")
or the {A07730B7-4100-457E-91E2-31BFF24E1EC4}
CLSID.
Although the object is published by the metadata library, it is
completely independent of the metadata and can be used in any script,
including those run outside of PlanetPress Suite.
Methods
|
Integer |
Add
(const String Key, Integer Value) |
|
Adds a new item in the sort list.
|
|
Clear
() |
|
Clears the sort list.
|
Integer |
Count
() |
|
Returns the number of elements in the
list.
|
|
Delete
(Integer Index) |
|
Removes an item from the sort list.
|
Integer |
Find
(const String Key) |
|
Finds an item in the list and returns its
index.
|
String |
Key
(Integer Index) |
|
Returns the key at the specified index.
|
|
Sort
() |
|
Sorts the list.
|
|
SortByValue
() |
|
Sorts the list based on the value instead
of the key.
|
Integer |
Value
(Integer Index) |
|
Returns the value at the specified index.
|
Method Documentation
Integer Add |
( |
const String |
Key, |
|
|
Integer |
Value |
|
|
) |
|
|
|
Adds a new string key in the list, with an optional associated
integer Value.
- Parameters:
-
|
Key |
String on which the sort will be performed. |
|
Value |
Optional integer associated with the string. This value
is not used and will not be changed by the sort class. If the string
goes to another position in the list after the sort, this value will
move as well to the new index of the string. |
- Returns:
- 0-based index of the newly added string. It is therefore always
equal to Count-1.
Empties the list, removing all the strings.
Returns the number of strings in the list.
- Returns:
- Number of strings in the list. If the list does not contain any
string, the return value is 0.
Removes a single string from the list.
- Parameters:
-
|
Index |
0-based index of the string to remove. |
- Exceptions:
-
|
EOleException |
Index is lower than 0 or higher than Count-1. |
Integer Find |
( |
const String |
Key |
) |
Finds a string and returns its position in the list.
- Parameters:
-
- Returns:
- 0-based index of the string. If the string is not found, the
method returns -1.
String Key |
( |
Integer |
Index |
) |
Returns the key at the specified index.
- Parameters:
-
|
Index |
0-based index of the string to retrieve. |
- Returns:
- Value of the key at the specified index.
- Exceptions:
-
|
EOleException |
Index is lower than 0 or higher than Count-1. |
Sorts the items in the list according to their key. The sort
performed is a simple alphabetical string sort: 30 comes after 200. The
strings are expected to be formatted correctly to return the desired
order (ex: "030", "200" will be sorted with 30 first and then 200).
Sorts the items in the list according to their value instead of the
key.
Integer Value |
( |
Integer |
Index |
) |
Retrieves the value of the optional integer at the specified index.
- Parameters:
-
|
Index |
0-based index of the value to retrieve. |
- Returns:
- The integer value at the specified index.
- Exceptions:
-
|
EOleException |
Index is lower than 0 or higher than Count-1. |