Jump to content
Sign in to follow this  

Stringsplit to 2D array

Recommended Posts


Hi guys

Im wondering if anyone can help me with StringSplit() and passing the results into a 2D array

I have a CSV log file i need to process

i use _filereadtoarray to read the file what i then wanted to to was step through the array and use stringsplit to make up a 2D array to then sort and search the log file.

#include <Constants.au3>

#include <Array.au3>

#include <file.au3>

Local $inputArray

If Not _FileReadToArray(@ScriptDir & "\expired.exp",$inputArray) Then

MsgBox(4096, "Error", " Error reading log to Array error:" & @error)



Local $mainArray[$inputArray[0]][12]

For $i = 1 TO 15 step 1

$mainArray[$i] = StringSplit($inputArray[$i],",")



When I run the above code i get the follwoing error

"check.au3 (18) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:"

I have also tried to set the array size manually to 2000 ranther than the size of $inputarray[0] incase the issue was related to creating the array size on the fly

im sure im missing something very simple but a pair of fresh eyes to nudge me in the right direction is always helpful



Share this post

Link to post
Share on other sites


you could try something like this. (not tested!)

#region ;************ Includes ************
#endregion ;************ Includes ************
; _csvTo2DArray

Local $re = _csvTo2DArray("c:BI-Repository.csv", ';')

Func _csvTo2DArray($file, $delim = ',')
Local $content = FileRead($file)
Local $rows_A = StringSplit(StringStripCR($content), @LF, 2)
StringReplace($rows_A[0], $delim, $delim)
Local $countColumns = @extended
Local $columns_A = 0

Local $2D_A[UBound($rows_A)][$countColumns + 1]

For $z = 0 To UBound($rows_A) - 1
$columns_A = StringSplit($rows_A[$z], $delim, 2)
For $y = 0 To UBound($columns_A) - 1
$2D_A[$z][$y] = $columns_A[$y]
Return $2D_A
EndFunc ;==>_csvTo2DArray
Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post

Link to post
Share on other sites

You could just read the file and use one of the UDF functions in example scripts to read your csv string.

or you could also try

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
Sign in to follow this