asiawatcher

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

5 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted

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

 

1 person likes this

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

#3 ·  Posted

Here a prior thread on the subject

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

cheers

Share this post


Link to post
Share on other sites

#5 ·  Posted

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