Collapse (?) An Array?

Richard Gaskin ambassador at fourthworld.com
Thu Sep 1 09:54:26 EDT 2011


Scott Rossi wrote:

> If I script this:
>
> put "A" into theArray[1]
> put "B" into theArray[2]
> put "C" into theArray[3]
>
>
> And then script this:
>
> delete variable theArray[2]
>
>
> I essentially get an array with entries that look like this:
>
> A
>
> C
>
> How can I collapse (?) the array after deleting element 2 so that the array
> only has two elements remaining?
>
> A
> C

The delete is fine; the problem is in the display of the results.

If you use:

   put theArray[1] &"*"&theArray[2] &"*"& theArray[3]

...you'll get the empty entry for theArray[2].  The variable theArray 
still exists, but there's nothing in that slot.

Building the output from the keys of the array will get what you want:

   put the keys of theArray into tKeys
   sort lines of tKeys -- if the order is important
   repeat for each line tKey in tKeys
      put "*"& theArray[tKey] after tResult
   end repeat
   put tResult


--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv




More information about the use-livecode mailing list