Arrays 比较.ini文件项的两个数组
我有一个.ini文件,如下所示:Arrays 比较.ini文件项的两个数组,arrays,autoit,Arrays,Autoit,我有一个.ini文件,如下所示: [Step] A=DONE B=DONE C=DONE D=DONE [Step] A=DONE C=DONE D=DONE 我需要获取[Step]部分并将其放入数组中。以下是我的工作: $iniSection_Step = "Step" $PrevStep = "" Local $Prev = IniReadSection($iniPath_LogFile, $iniSection_Step) For $i = 1 To $Prev[0
[Step]
A=DONE
B=DONE
C=DONE
D=DONE
[Step]
A=DONE
C=DONE
D=DONE
我需要获取[Step]
部分并将其放入数组中。以下是我的工作:
$iniSection_Step = "Step"
$PrevStep = ""
Local $Prev = IniReadSection($iniPath_LogFile, $iniSection_Step)
For $i = 1 To $Prev[0][0]
$PrevStep = $PrevStep &"|"& $Prev[$i][0]
Next
Global $PrevArray = StringSplit($PrevStep,"|",1)
\u ArrayDisplay()
结果:
Row|Col 0
[0]|5
[1]|
[2]|A
[3]|B
[4]|C
[5]|D
现在我需要将数组与另一个数组进行比较,如果两个数组中都存在一个元素,它将增加一个数组
For $j = 0 To UBound($array_StepComplete) - 1
if StringInStr($array_StepComplete[$j],$PrevArray[$i]) Then
GUICtrlSetData($Input_PresentStep,$array_StepComplete[$j+1])
EndIf
Next
这将增加一个数组,但如果有人删除.ini文件的内容,如下所示:
[Step]
A=DONE
B=DONE
C=DONE
D=DONE
[Step]
A=DONE
C=DONE
D=DONE
代码将递增一个数组,但不会检查元素是否存在。我的理解是:
比较两个数组,如果两个元素匹配,则执行一些操作。
首先你需要把事情弄清楚你想比较什么?明显的顺序很重要。。所以我决定先在动态数组上循环,如果我找到了匹配的对,我也会出于资源原因退出循环
Local $aSteps = IniReadSection("Steps.ini", "Step")
If @error Then
ConsoleWrite("#1 An error occured while reading the 'Steps.ini' file." & @CRLF)
Exit
EndIf
Local $aAllsteps = IniReadSection("Steps.ini", "Allsteps")
If @error Then
ConsoleWrite("#2 An error occured while reading the 'Steps.ini' file." & @CRLF)
Exit
EndIf
; loop on the dynamical array first
For $i = 1 To $aSteps[0][0]
; then loop on the static array for each element
For $y = 1 To $aAllsteps[0][0]
; check if the elements match
If $aSteps[$i][0] = $aAllsteps[$y][0] Then
; if the element match print out and exit loop for resource reason
ConsoleWrite("MATCH - " & $aSteps[$i][0] & @CRLF)
ExitLoop
EndIf
Next
Next
Steps.ini
[Step]
A=DONE
C=DONE
D=DONE
[Allsteps]
A=DONE
B=DONE
C=DONE
D=DONE
输出
MATCH - A
MATCH - C
MATCH - D