Xbasic
Array reorder Method
Syntax
V <array>.reorder(numbers as c)
Arguments
- numbersCharacter
The sequence of array elements, as produced by the <array>.property_order() method.
Description
Reorder array elements.
Discussion
The <array>.reorder() method reorders an array based on an order list of the numbers of array elements. Use the <array>.property_order() method to create the order list.
Example
Create an array named arr and populate it with name and desc properties.
dim data as C
data = <<%str%
One|first one
Two|second one
Three|third one
%str%
dim arr[3] as P
arr.initialize_properties("name|desc", data)
? arr
+[1].
+[2].
+[3].
? arr[1]
= desc = "first one "
name = "One"
? arr[2]
= desc = "second one "
name = "Two"
? arr[3]
= desc = "third one "
name = "Three"Define an arbitrary order for the name property in the array.
dim refList as C
refList = comma_to_crlf("Two,One,Three")
? reflist
= Two
One
ThreeCreate a string that defines how the array should be reordered.
ord = arr.property_order("name", refList)
? ord
= 2
1
3Now sort the array based on this new order.
arr.reorder(ord)
? arr.dump_properties("name|desc")
= Two|second one
One|first one
Three|third oneSee Also