Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

 

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

  • Recently Browsing   0 members

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