Sign in to follow this  
Followers 0
igorm

2 Arrays with a lot of data

5 posts in this topic

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

Share this post


Link to post
Share on other sites



@igorm...Try _FileWriteFromArray().

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

My bad...you are 100% correct...

Dyslexia :P

Edited by DjDeep00

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