2017-05-04 85 views
-1

的两个数组我有如下一个.ini文件:比较.ini文件条目

[Step] 
A=DONE 
B=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) 

_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 

    C=DONE 
    D=DONE 

的代码将增加一个阵列,但如果元素存在,它不检查。

回答

0

我明白了什么:Compare two arrays and do some action if two elements match.

首先,你需要明确的事情了。 你想比较什么?为了明显事情确实 ..所以我决定循环动力学阵列上第一,如果我找到了一个匹配对我也退出了资源的原因,环...

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