Jump to content
asiawatcher

How dol i splitstring a string into a 2d array ?

Recommended Posts

asiawatcher

i have this string  0,6,36,4,25,22,1,35,9,5,28,3,29,3,20,25,18,31,8,4,11

 

i know this example

 

Example()

Func Example()
    Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri,Sat,Sun", ",") ; Split the string of days using the delimiter "," and the default flag value.
    #cs
        The array returned will contain the following values:
        $aDays[1] = "Mon"
        $aDays[2] = "Tues"
        $aDays[3] = "Wed"
        ...
        $aDays[7] = "Sun"
    #ce

    For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
        MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i])
    Next
EndFunc   ;==>Example

but i want to insert it into a 2d array in group[s of 2 like 

 

0 - 6

36 - 4

25 - 22

1 - 35

etc..

 

without the - of course how do we do this ? cheers

 

Edited by asiawatcher

Share this post


Link to post
Share on other sites
water

Always process two rows at once:

For $i = 1 To $aDays[0] Step 2 ; Loop through the array returned by StringSplit to display the individual values.
    MsgBox($MB_SYSTEMMODAL, "", $aDays[$i] & " " & $aDays[$i + 1])
Next

 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
asiawatcher

cheers

Share this post


Link to post
Share on other sites
Malkey

Here is an example of a coma separate string to a two column 2D array.

#include <Array.au3>

Local $str = "0,6,36,4,25,22,1,35,9,5,28,3,29,3,20,25,18,31,8,4,11"
$array = StringSplit($str, ",", 2) ;  (2) = disable the return count in the first element. 

$aArray2D = _Array1DTo2D($array, 2) ; 2 parmeter for return 2 columns  in 2A array.
_ArrayDisplay($aArray2D)


Func _Array1DTo2D(ByRef $aArray1D, $iNumberOfCols)
    Local $aRet[Ceiling(UBound($aArray1D) / $iNumberOfCols)][$iNumberOfCols]
    For $i = 0 To UBound($aArray1D) - 1
        $aRet[Int($i / $iNumberOfCols)][Mod($i, $iNumberOfCols)] = $aArray1D[$i]
    Next
    Return $aRet
EndFunc   ;==>_Array1DTo2D

 

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

×