Jump to content

Recommended Posts

Posted (edited)

Hi,

What I need is to split 1D array into 2D array and to have something like:

           Col0 Col1    Col2 

Row0 B      Erik     Erikson

Row1 A     John    Johnson

I am trying to use help file and made something what does not work :(

;My $ArrayUnique is this:
;Row    Col 0
;[0]    B,Erik,Erikson
;[1]    A,John,Johnson
;[2]    A,Martin,Martinson
;[3]    E,Olaf,Olafson
   
    Local $aUniqueSplited[1][3]

        For $i = 0 To UBound($ArrayUnique) - 1
            Local $sText = $ArrayUnique[$i] 
            Local $aArray = StringSplit($sText, ',') 

            For $y = 1 To $aArray[0] 
                For $z = 0 To UBound($ArrayUnique) - 1
                    $aUniqueSplited[$z][$y-1] = $aArray[$y]
                Next
            Next
        Next

First I create new array to be filled, but I dont know how many rows I am gonna have. Could be from 1 to 100 maybe.

I need 3 columns, so this part is OK.

And then it breaks here if I set my array to 1 row and I actually have 4 like in this example: $aUniqueSplited[$z][$y-1] = $aArray[$y]

If I set row number to 4, then it fills all array with B Erik Erikson.

 

What am I doing wrong?

 

Edited by stick3r
Posted

let the UDFs do the heavy lifting

#include<array.au3>

local $arr = ["B,Erik,Erikson" , "A,John,Johnson" ,"A,Martin,Martinson" , "E,Olaf,Olafson"]
local $aOut[0][3]

_ArrayAdd($aOut , _ArrayToString($arr) , 0 , "," , "|" , 1)

_ArrayDisplay($aOut)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...