#47242 - 2003-10-23 06:19 PM
Arrays
|
Saad
Lurker
Registered: 2003-10-23
Posts: 1
|
How can I either add multiple elements to an existing array with elements, append one array to another or merge two arrays.
Thanks.
|
Top
|
|
|
|
#47244 - 2003-10-23 06:45 PM
Re: Arrays
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Heres a quick little UDF for it. Call it like this:
code:
$Array1 = 0,1,2,3,4
$Array2 = 5,6
$Array3 = AddArrays($Array1, $Array2)
For $i = 0 to UBound($Array3) ?"Element=" $Array3[$i] Next
exit 1
Heres the source, not sure if there is already a UDF for this or not ...
code:
Function AddArrays($Array1, $Array2) ; Returns a new $Array1 Dim $n,$i $n = UBound($Array1) + 1 REDIM PRESERVE $Array1[$n+UBound($Array2)] For $i = 0 to UBound($Array2) $Array1[$n+$i] = $Array2[$i] Next $AddArrays = $Array1 EndFunction
[ 23. October 2003, 19:27: Message edited by: Shawn ]
|
Top
|
|
|
|
#47250 - 2003-10-23 07:50 PM
Re: Arrays
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
one of those cases where golfing can hurt your code preformance
|
Top
|
|
|
|
#47254 - 2003-10-24 04:44 AM
Re: Arrays
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
I can't speak for Saad but THANKS! I was just needing this very thing. I did a quick search through the UDFs on Wed and didn't find anything, so unless anyone knows differently, I think this is a prime addition to the UDFs.
|
Top
|
|
|
|
#47255 - 2003-10-24 01:31 PM
Re: Arrays
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
hmmm... I just jumped on the UDF post without reading this one...
It would be a better internal kix function
$array3=$array1+$array2
But Shawn's UDF works just as well... and gets past the CHR limitation
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|