0
我有一個數組查找IP匹配通過VBScript中
arrIP={"10","144","26,"0"}
and another array
arrItc={"10","126","0","0"}
我要檢查前三個值相等,然後返回一個布爾值,如果所有三個相等
我有一個數組查找IP匹配通過VBScript中
arrIP={"10","144","26,"0"}
and another array
arrItc={"10","126","0","0"}
我要檢查前三個值相等,然後返回一個布爾值,如果所有三個相等
另一個想法來測試。
a1 = Array("10", "144", "26", "0")
a2 = Array("10", "126", "0", "0")
a3 = Array("10", "144", "26", "1")
a1(UBound(a1)) = ""
a2(UBound(a2)) = ""
a3(UBound(a3)) = ""
WScript.Echo "a1=a2 ? " & (Join(a1) = Join(a2))
WScript.Echo "a2=a3 ? " & (Join(a2) = Join(a3))
WScript.Echo "a1=a3 ? " & (Join(a1) = Join(a3))
'Result:
a1=a2 ? False
a2=a3 ? False
a1=a3 ? True
使用布爾表達式或循環:
Option Explicit
Dim aTests : aTests = Array(_
Split("10 144 26 0") _
, Split("10 144 26 0") _
, Split("10 144 26 1") _
, Split("10 144 27 0") _
, Split("10 145 26 0") _
, Split("11 144 26 0") _
)
Dim nTest
For nTest = 1 To UBound(aTests)
WScript.Echo Join(aTests(0)), "?", Join(aTests(nTest)), CStr(cmp3(aTests(0), aTests(nTest)))
Next
Function cmp3(aL, aR)
cmp3 = aL(0) = aR(0) And aL(1) = aR(1) And aL(2) = aR(2)
End Function
Function cmp3(aL, aR)
cmp3 = False
Dim i
For i = 0 To 2
If aL(i) <> aR(i) Then Exit Function
Next
cmp3 = True
End Function
輸出:
10 144 26 0 ? 10 144 26 0 Wahr
10 144 26 0 ? 10 144 26 1 Wahr
10 144 26 0 ? 10 144 27 0 Falsch
10 144 26 0 ? 10 145 26 0 Falsch
10 144 26 0 ? 11 144 26 0 Falsch
非常感謝.. :) – Stackie