Jump to content

2 Arrays with a lot of data


igorm
 Share

Recommended Posts

Hi,

I have a 2 arrays which sometimes contain up to 4165 elements. I need to write all those elements to text file. I'm using this:

$array1 = stringsplit($mydata1, "=")
$array2 = stringsplit($mydata2, "=")

Arrays have same numbers of elements so next part of code is this:

for $i=1 to array1 [0]
iniwrite("textfile.txt", "File", array1[$i], $array2[$i])
next

This works fine, but it's painfully slow. Is there any way I can speed this up, or there is some other way I can export all data from array to text file?

Exported text file needs to have INI file form:

[File]
Key=Value

Thanks in advance for any help.

Cheers :P

Link to comment
Share on other sites

Hi,

I have a 2 arrays which sometimes contain up to 4165 elements. I need to write all those elements to text file. I'm using this:

$array1 = stringsplit($mydata1, "=")
$array2 = stringsplit($mydata2, "=")

Arrays have same numbers of elements so next part of code is this:

for $i=1 to array1 [0]
iniwrite("textfile.txt", "File", array1[$i], $array2[$i])
next

This works fine, but it's painfully slow. Is there any way I can speed this up, or there is some other way I can export all data from array to text file?

Exported text file needs to have INI file form:

[File]
Key=Value

Thanks in advance for any help.

Cheers :P

What takes so long in the many iterations of Open/Write/Close on the file. If you assemble it all as a string in memory and then write it once, it will be very fast:
$sIniFile = "TestFile.txt"
$sIniData = "[File]" & @CRLF
for $i=1 to $array1[0]
    $sIniData &= $array1[$i] & "=" & $array2[$i] & @CRLF
next
FileWrite($sIniFile, $sIniData)

The _FileWriteFromArray() suggestion won't work because you are assembling data from two arrays into INI format.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...