Jump to content
oasis375

Array joining. Language limitation?

Recommended Posts

oasis375

Say I have two arrays:

Local $aArray1[3] = ["one", "two", "three"]

Local $aArray2[3] = [1, 2, 3]

And I want to join them into a simgle 2D Array, resulting in:

$aArray[2][3] = [["one", "two", "three"] , [1, 2, 3] ]

I remember that, with other languages, it's possible to simply do:

$aArray[2][3] = [ $aArray1, $aArray2]

Is there a direct method like this to join arrays, (not by using a loop).

Edited by oasis375

Share this post


Link to post
Share on other sites
JLogan3o13

Look at _ArrayConcatenate in the help file

#include <Array.au3>

Local $a1[5] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
Local $a2[2] = ["Saturday", "Sunday"]

_ArrayDisplay($a1, "Before")
_ArrayDisplay($a2, "Before")

_ArrayConcatenate($a1, $a2)
_ArrayDisplay($a1, "After")

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
oasis375

Yes, I know how to concatenate two 1D arrays. If you read again my question, you'll notice that I'm talking about a multidim array. I'm trying to join two 1D arrays into a 2D array (with 2 columns).

$aArray[2][3] = [["one", "two", "three"] , [1, 2, 3] ]

Not the same as:

$aArray[6] = ["one", "two", "three", 1, 2, 3]

 

Share this post


Link to post
Share on other sites
water

No, there is no direct method to do what you want to do.
You have to code it yourself. But that's not too hard ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
czardas

Your arrays are in the wrong orientation. You can use _Predim() to do this - or _ArrayTranspose(). See ArrayWorkshop in my signature.

#include <Array.au3>
#include 'ArrayWorkshop.au3'

Local $aArray1[3] = ["one", "two", "three"]
Local $aArray2[3] = [1, 2, 3]

_Predim($aArray1, 2, True) ; specific to your request
_Predim($aArray2, 2, True)

_ArrayAttach($aArray1, $aArray2)
_ArrayDisplay($aArray1)

Oops, ignore what I just said. Your array declaration syntax is incorrect. 2 columns is easier: simply just attach the arrays in the second dimension.

#include <Array.au3>
#include 'ArrayWorkshop.au3'

Local $aArray1[3] = ["one", "two", "three"]
Local $aArray2[3] = [1, 2, 3]

_ArrayAttach($aArray1, $aArray2, 2)
_ArrayDisplay($aArray1)

 

Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.