PDA

View Full Version : Combine arrays?


Adam - FMM
02-02-07, 02:47 AM
Let us say I have 2 arrays:

<MvASSIGN NAME = "l.array1" INDEX="{l.1}" VALUE = "{l.var}">
<MvASSIGN NAME = "l.array2" INDEX="{l.2}" VALUE = "{l.var2}">

my script runs and the contents of l.array1 is

1
2
3

the contents of l.array2 is

a
b
c
d

Is it possible to run the first array against the second, concotenate the contents and get an output of all 12 combinations - and in this order?

1a
1b
1c
1d
2a
2b
2c
2d
3a
3b
3c
3d

Thanks

mvmarkus
02-02-07, 10:26 AM
Hi Adam,

Combining these two arrays is pretty simple when you use two nested loops:

<MvASSIGN NAME = "l.a" VALUE = "1" >
<MvWHILE EXPR = "{ l.array1[l.a] }">
<MvASSIGN NAME = "l.b" VALUE = "1" >
<MvWHILE EXPR = "{ l.array2[l.b] }">
<MvASSIGN NAME = "l.result" INDEX="{miva_array_max( l.result)+1}" VALUE = "{ l.array1[l.a]$ l.array2[l.b] }" >
<MvASSIGN NAME = "l.b" VALUE = "{ l.b+1 }" >
</MvWHILE>
<MvASSIGN NAME = "l.a" VALUE = "{ l.a+1 }" >
</MvWHILE>

l.result gives you the result you wanted.

Markus

Adam - FMM
02-02-07, 07:28 PM
I thought it was something like that, just could'nt get my head around it.

I notice the out put seems to have a phantom comma included between each result line.

1a
,1b
,1c
,1d
,2a
,2b
,2c
,2d
,3a
,3b
,3c
3d

Where is that coming from?

Vic - WolfPaw Computers
02-02-07, 07:30 PM
It MAY be here:

{ l.array1[l.a]$ l.array2[l.b] }

Try { l.array1[l.a] $ l.array2[l.b] }

Note the space before and after the $.

Adam - FMM
02-02-07, 10:21 PM
Yeah, that was why. I had to modify this for my final application, but that shove in the right direction was what I needed. *Sends Vic and Markus virtual brewskis*