Jump to content
Sign in to follow this  
GordonFreeman

Copy IniReadSection Array to other array

Recommended Posts

GordonFreeman

Hi guys!

I need to copy the array returned by inireadsection to another array that will keep all information

IniFile looks (test.ini):

[test1]

1=test11

2=test12

3=test13

[test2]

1=test21

2=test22

3=test23

How can i do it?

I think the other array like how:

Global $aData[2][3]

 

Share this post


Link to post
Share on other sites
kylomas

Are you saying that you want to copy each section as a row and each key as a column of each row?

Like...

                                      col[0]    col[1]     col[2]

row [0] -             test1   test11   test12    test13

row [1] -             test2   test21   test22    test23


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
GordonFreeman

Yes. but col 0 start with test1 and test2 / in row 0 & 1

by example:

Global $aData[2][3]=[["test11","test12","test13"],["test21","test22","test23"]]

I can do it with for but i not think if is a fatest / better way 

Edited by GordonFreeman

Share this post


Link to post
Share on other sites
kylomas

Using an ini file that looks like this...

[test1]
1=test11
2=test12
3=test13
[test2]
1=test21
2=test22
3=test23
[test3]
1=test31
2=test32
3=test33
4=test34
5=test35

 

I'm using "for..to" loops like this...

#include <array.au3>

local $inifile = @scriptdir & '\test.ini'
local $aSect = inireadsectionnames($inifile), $aTmp

; defiine result array - rows = number of sections, columns = 1
local $aData[ubound($aSect)-1][1]

; loop through sections reading each
for $1 = 1 to $aSect[0]
    $aTmp = inireadsection($inifile,$aSect[$1])
    if @error then
        ConsoleWrite('ini file read section error = ' & @error & @LF)
        Exit
    endif

    ; redefine # of columns if section contains more than currently defined
    if ubound($aTmp) > ubound($aData,2) then redim $aData[ubound($aData)][ubound($aTmp)]

    ; set row to section name
    $aData[$1-1][0] = $aSect[$1]

    ; loop through section key/values pairs populating result array with "value"
    for $2 = 1 to $aTmp[0][0]
        $aData[$1-1][$2] = $aTmp[$2][1]
    next
Next

_arraydisplay($aData)

Are you saying that this is not fast enough?

kylomas

edit: ambiguous comment

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
jchd

Just copy the array by assigning it to another variable:

Local $aSectionread = IniReadSection(...)
Local $aSDup = $aSectionRead

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

×