# How to add array to array?

## Recommended Posts

I have an array \$array1 (0,1,2,3,4) and another array \$array2 (5,6,7,8) and i need to add \$array2 to \$array1 so that \$array1 would become (0,1,2,3,4,5,6,7,8). How to do that?

I found function _ArrayAdd from the help file but I think it just puts the another array inside one array element so that \$array1 would become (0,1,2,3,4,(5,6,7,8)). Am I right about that one?

##### Share on other sites

I have an array \$array1 (0,1,2,3,4) and another array \$array2 (5,6,7,8) and i need to add \$array2 to \$array1 so that \$array1 would become (0,1,2,3,4,5,6,7,8). How to do that?

I found function _ArrayAdd from the help file but I think it just puts the another array inside one array element so that \$array1 would become (0,1,2,3,4,(5,6,7,8)). Am I right about that one?

Try this:

```Dim \$array1[5]
Dim \$array2[4]
For \$i = 0 to Ubound(\$array1)-1
\$array1[\$i] = \$i
Next
For \$i = 0 to Ubound(\$array2)-1
\$array2[\$i] = \$i + 5
Next
For \$i = 0 to Ubound ( \$array2 ) -1
Redim \$array1[Ubound(\$array1)+1]
\$array1[Ubound(\$array1)-1] = \$array2[\$i]
Next
\$Msg = ''
For \$i = 0 To UBound ( \$array1 ) -1
\$Msg = \$Msg & \$array1[\$i]
Next
MsgBox ( 0, @ScriptName, \$Msg )```
Edited by JerryD

##### Share on other sites

Hi,

Or if you prefer (like me!) to use UDFs;

;ArrayConcat.au3 ; 0_1

#include<Array.au3>

#include<Array2.au3>

\$array1 =_StringSplit_B0("0,1,2,3,4",",")

\$array2 =_StringSplit_B0("5,6,7,8",",")

; Here it is....

\$array1 =_StringSplit_B0(_ArrayToString(\$array1,"|")&"|"&_ArrayToString(\$array2,"|"))

_ArrayDisplay(\$array1,"\$array1")

Best, Randall

##### Share on other sites

Thanks a lot, i got the point.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...