The Array Helper file contains handlers that assist in working with arrays.
Loading this Helper
This helper is loaded using the following code:
The following handlers are available:
Lets you fetch an item from an array. The function tests whether the array index is set and whether it has a value. If a value exists it is returned. If a value does not exist it returns FALSE, or whatever you've specified as the default value via the third parameter. Example:
put "color=red,shape=round,size=" into tArray split tArray using comma and "=" -- returns "red" get rigArrayElement("color", tArray) -- returns 0 get rigArrayElement("size", tArray, 0)
Takes an array as input and returns a random element from it. Usage example:
put "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson" into tQuotes put "Don't stay in bed, unless you can make money in bed. - George Burns" into tQuotes put "We didn't lose the game; we just ran out of time. - Vince Lombardi" into tQuotes put "If everything seems under control, you're not going fast enough. - Mario Andretti" into tQuotes put "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein" into tQuotes put "Chance favors the prepared mind - Louis Pasteur" into tQuotes put rigArrayRandElement(tQuotes) into gData["quoteOfTheDay"]
Takes an array as input and returns the keys of the array as numeric array.
Returns all the values from the input array and indexes the array numerically.
rigArraySplice(tArray, tOffset, tLength)
Retrieve a portion of an array. Example:
put "red,blue,green,yellow,violet,black,white" into tArray split tArray using comma put rigArraySplice(tArray, 2, 3) into tSplicedArray combine tSplicedArray using comma -- Produces: green,yellow,violet
Note: This works with numbered arrays only as LiveCode's arrays are not ordered.
Joins array elements with a string. Example:
put "red,yellow,blue,green" into tArray split tArray using comma get rigImplode(tArray, " - ") -- Produces: red - yellow - blue - green
Returns a list of array elements, each on a seperate line.