'Flattening'/storing arrays
Dar Scott
dsc at swcp.com
Mon Dec 16 15:44:01 EST 2002
On Monday, December 16, 2002, at 12:59 PM, James Witte wrote:
> Is there a way to built-in (or already written) way to 'flatten' an
> array or otherwise store it in something other than a property attached
> to an object (which would neccesitate data files being actual stacks)
Under most circumstances you can use the combine command to flatten and
the split command to unflatten. These are commands that operate on an
array, so you might need to copy the array.
You will need two delimiters that are not in the keys and elements. I
imagine even weird control characters will work for these. If you store
binary data, such as images, then you don't meet these requirements.
(Unless the binary data is made text.) See below if you need binary
keys or elements.
Keys are strings. Elements may be internal numbers as well as arbitrary
strings. These are converted to strings using the information in the
numberFormat property. That means that unless you are careful, you
might end up with big strings for large numbers or information lost for
small numbers. If you don't store numbers, don't worry about it.
If you need to save arbitrary arrays that may have any character (byte)
in them, you need to go to a fancier method. I am working on one as
part of my nodes-or-boxes-or-whatever project. I can make that
available early if this is important to you. I have not tested my
method yet, but I expect it to work. It will be slower than combine,
but it should be suitable for data to be stored in a file.
So... Look in the TD for "combine", "split" and "numberFormat".
Dar Scott
More information about the use-livecode
mailing list