Sign in to follow this  
Followers 0
smasher953

reading a .ini file into a multidimensional array

3 posts in this topic

I've been playing around all morning trying to do this and I'm getting no where fast. I'm trying to read an entire .INI file into a multidimensional array. The size of the .INI file is different every time the file will be read. Here's a sample of the .INI contents:

[COSMI]

LastFound=11/29/2004

CountFound=2

LastRemoved=11/29/2004

CountRemoved=1

[WebDialer]

LastFound=11/29/2004

CountFound=3

LastRemoved=11/29/2004

CountRemoved=2

[AdGoblin]

LastFound=11/29/2004

CountFound=2

LastRemoved=11/29/2004

CountRemoved=1

[Adtomi.YahooStocks]

LastFound=12/1/2004

CountFound=7

[blazeFind.SearchEnhancer.ISTbar]

LastFound=11/29/2004

CountFound=2

LastRemoved=11/29/2004

CountRemoved=1

[ClearSearch.Net]

LastFound=11/30/2004

CountFound=3

LastRemoved=11/30/2004

CountRemoved=4

[CoolWWWSearch.008k]

LastFound=11/29/2004

CountFound=2

LastRemoved=11/29/2004

CountRemoved=1

I'd like each "[*]" section to be put into a row, and then each LastFound, CountFound, LastRemoved, CountRemoved put into a seperate column in that row. Any quick and easy ways to do this effectively? I've search the forum and found some things, but nothing to specifically help me out.

--greg

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is one way to do it, if your data stays in this format.

$file="test.ini"
$filelines=Fileread($file,filegetsize($file))
$counter=StringSplit($filelines,"[")
$filelines=StringSplit(StringReplace(StringReplace($filelines,@lf,@cr),@cr&@cr,@cr),@cr)
$counter=$counter[0]-1
Dim $items[$counter][5]
$c=-1

for $i=1 to $filelines[0]
Select
Case StringLeft($filelines[$i],1)="["
   $c=$c+1
   $items[$c][0]=$filelines[$i]
Case StringLeft($filelines[$i],9)="LastFound"
   $items[$c][1]=$filelines[$i]
Case StringLeft($filelines[$i],10)="CountFound"
   $items[$c][2]=$filelines[$i]
Case StringLeft($filelines[$i],11)="LastRemoved"
   $items[$c][3]=$filelines[$i]
Case StringLeft($filelines[$i],12)="CountRemoved"
   $items[$c][4]=$filelines[$i]
EndSelect
next


for $i=0 to $counter-1
   MsgBox(1,$items[$i][0],$items[$i][1] &@cr& $items[$i][2] &@cr& $items[$i][3] &@cr& $items[$i][4])  
Next
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

That worked! I was missing 1 thing out of it....Thanks for the help scriptkitty!

--greg

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  
Followers 0