Split, combine ok but where's extract?

Alex Tweedly alex at tweedly.net
Sat Feb 12 18:25:01 CST 2005

David Vaughan wrote:

> On 13/02/2005, at 4:00, MisterX" <b.xavier at internet.lu> wrote:
> Xavier
> I have not searched back to your original request, but if I understand 
> it correctly then you wish to be able to de-merge columns from an 
> array, and that these columns may be of the data or of the keys. Let 
> us assume you have an array where an element is defined by:
> put "n1,n2" into myArray[a,b]
> Here, you can extract anything from the keys or the element using 
> split and combine. For example, this code places all four columns in 
> separate variables  v1-v4 (untested)
> put the keys of myArray into tKeys
> split tKeys with return and comma
> put the keys of tKeys into v1
> combine tKeys   -- discards the keys
> put tKeys into v2
> combine myArray  -- discards the keys
> split myArray with return and comma
> put the keys of myArray into v3
> combine myArray
> put myArray into v4
> Now, v1=a, v2=b, v3=n1, v4=n2
> (or close enough if I made a coding error)
> I have a column merge function somewhere. I will look it up to see if 
> it is any improvement over what you have.

I may have missed something in the original problem description, but I 
think there's a problem with this scheme.

If you take the case of
   put "1,2" into myArray[a,b]
   put "1,3" into myarray[c,d]

I believe what Xavier wants (at least, what his posted code gives - 
though it used a simple table not keys) is
 v1 = a,c
 v2 = b,d
 v3 = 1,1
 v4 = 2,3

Note particularly v3 - using the various "repeat" forms, it has each 
item from the column.

split/combine will remove duplicates - and hence give
 v1 = a,c
 v2 = b,d
 v3 = 1
 v4 = 2,3

There's a similar problem with the merge code - repeated values in a 
column cause loss of data.

Alex Tweedly       http://www.tweedly.net

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005

More information about the use-livecode mailing list