Jump to content
Sign in to follow this  
computergroove

Adding a splitstring array to a seperate 2d array

Recommended Posts

computergroove

Ini file:

12345=file1.avi
23456=file2.avi
34567=file3.avi

My current code:

_FileReadToArray($DBLocation,$DBArray,4);Reads ini file to to 1d array seperated line by line with a crlf
For $i = 1 To Ubound($DBArray)
     $Temp = StringSplit($DBArray[$i],"=",1)
     _ArrayAdd($DB2DArray,$Temp[$i])
     _ArrayDisplay($DB2DArray)
Next

I want to put the splitstring from the ini file into the top line of the array.

So the top line of $DB2DArrray[1] will be 12345 in the first column and file1.avi in the second column

Whats the best way to do this?

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
Melba23

computergroove,

As long as the file only contains lines in the "xxx=yyy" format you can do it very easily: ;)

#include <Array.au3>
#include <File.au3>

; Define variable
Local $aSplitArray
; Split array when reading - define delimiter to use
_FileReadToArray($sIni, $aSplitArray, $FRTA_NOCOUNT, "=")
; Display result
_ArrayDisplay($aSplitArray, "Split", Default, 8)
If there are other lines in the file you will need to take another route. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
computergroove

What is $sIni? I have between 1 and 5000 lines like 12345=file1.avi. I want them all to be read into an array. Column 1 will be 12345 and column 2 will be file1.avi.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
Melba23

computergroove,

$sIni is the path to the ini file you said you wanted to read. ;)

 

I have between 1 and 5000 lines

That is not the question I asked. The code I suggested will only work if there all lines in the file are in the "xxx=yyy" format - the number of lines does not matter. If you have any lines which do not have that format then you will have to use another technique - most probably something along the lines of the code in the OP. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×