Reputation: 43
Let's say I have an .ini file with the following key value pairs
[keys]
a:"apple"
b:"banana"
o:"orange"
How can I read these key,value pairs into an object (associative array) in my script?
Upvotes: 0
Views: 1145
Reputation: 851
This should work for you.
A:=Object() ;Create Array/Object
Loop, read, listing.txt ;loop through file
{
IfInString, A_LoopReadLine, [keys] ;if line has [keys] in it continue
{
continue
}
;fill array with line split on :
A[StrSplit(A_LoopReadLine, "`:").1] :=StrSplit(A_LoopReadLine, "`:").2
}
;print key , value for A
For key, value in A
MsgBox %key% = %value%
Upvotes: 3