如何将 .ini 文件中的所有键值对读入一个对象?
How can I read all the key-value pairs in .ini file into an object?
假设我有一个包含以下键值对的 .ini 文件
[keys]
a:"apple"
b:"banana"
o:"orange"
如何将这些键值对读入脚本中的对象(关联数组)?
这应该适合你。
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%
假设我有一个包含以下键值对的 .ini 文件
[keys]
a:"apple"
b:"banana"
o:"orange"
如何将这些键值对读入脚本中的对象(关联数组)?
这应该适合你。
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%