dick.kriesel at mail.com
Fri Jun 15 22:21:55 CDT 2012
On Jun 15, 2012, at 3:21 PM, Bob Sneidar wrote:
> Hi all.
> I am wondering if anyone has developed an Array Filter procedure that would give me all the rows of an array matching a certain criteria? For instance, let's say I wanted all the rows whose key "name" contained "bob" and have it returned as an array of the same structure containing only those records?
> If not I am going to have to write one.
Hi, Bob. Here's an example for a simple array. Put it into a script and run "test1" from the message box.
Does it work for you?
function subarrayForNameContainsString @rArray, pString
repeat for each key tKey in rArray
if rArray[ tKey ][ "name" ] contains pString then
put rArray[ tKey ] into tArray[ tKey ]
local tArray, tSubarray
put "Betty" into tArray[ 123 ][ "name" ]
put "Bob" into tArray[ 234 ][ "name" ]
put "carpenter" into tArray[ 234 ][ "occupation" ]
put subarrayForNameContainsString( tArray, "Bob" ) into tSubarray
More information about the use-livecode