Jump to content

merge 1d arrays to 2d


ur
 Share

Recommended Posts

I have a string with comma seperated as below.

Name="Test-win10x64,Test-win10x65,Test-win10x67"

$machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT)

with the above line i can get a single dimension array.

But I want a tabular format array like 4X4 where I want to add the 4 single dimension arrays as different columns in them.

 

Is there any option to do the same.

Link to comment
Share on other sites

Since you said 4X4 I added another entry to your string. Try the following code, is that what you want?

 

#include <Array.au3>

$tempINIValue = "Test-win10x64,Test-win10x65,Test-win10x67,Test-win10x68"
$machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT)

Global $aTable[4][4]

For $i = 0 to UBound($aTable, 1) - 1
    $aTable[0][$i] = $machine_names[$i+1]
Next

_ArrayDisplay($aTable)

 

If not please elaborate further :)

Link to comment
Share on other sites

Maybe this.

#include <Array.au3>

Local  $sName="Test-win10x64,Test-win10x65,Test-win10x67,Test-win10x69"

;Arrays
Local $machine_names = StringSplit($sName, ',', 2) ;  $STR_NOCOUNT (2)
Local $aItem1 = ["A", "B", "C", "D"]
Local $aItem2 = [1, 2, 3, 4]
Local $aItem3 = ["up", "down", "left", "right"]

Local $Arrays = [$machine_names, $aItem1, $aItem2, $aItem3] ; Array of array names.

$aCombined2D = _Arrayombine($Arrays)
_ArrayDisplay($aCombined2D)


Func _Arrayombine($Arrays)
    Local $iRows = UBound($Arrays[0], 1), $iCols = UBound($Arrays)
    Local $a[$iRows][$iCols]
    For $i = 0 To $iRows - 1
        For $j = 0 To $iCols - 1
            $a[$i][$j] = ($Arrays[$j])[$i]
        Next
    Next
    Return $a
EndFunc   ;==>_Arrayombine

 

Link to comment
Share on other sites

11 minutes ago, Subz said:

Or

#include <Array.au3>

$tempINIValue = "Test-win10x64,Test-win10x65,Test-win10x67,Test-win10x68"
$machine_names = StringSplit($tempINIValue, ',', 3)
_ArrayTranspose($machine_names)
_ArrayDisplay($machine_names)

 

 

I didn't even know this function exists. The more you know :D

Link to comment
Share on other sites

You could also try my _ArrayAttach() function from ArrayWorkshop.au3 (see my signature below)

#include <ArrayWorkshop.au3>

Local $array1 = [1,2,3]
Local $array2 = [4,5,6]

_ArrayAttach($array1, $array2, 2) ; attach columns (i.e. 2nd dimension)

 

Edited by czardas
Link to comment
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
 Share

×
×
  • Create New...