vbscript中两个数组的比较

时间:2016-03-22 21:20:06

标签: arrays vbscript

有没有办法比较两个相同大小的数组。重要的是,数组的维度可以大于1。

例如,它可能是一个函数,只有当索引为(i, j, k, ...)的数组arrA的元素等于所有索引的索引为False的数组arrB的元素时才取值为True;其他案例的值为"For Each...In arrA"。我知道有使用"For i=LBound(arrA,1) to UBound(arrA,1)...Next"或至少嵌套 var button = new Button(); var image = new ImageBrush(); image.ImageSource = new BitmapImage(new Uri(url, UriKind.Absolute)); button.Background = image; 的诱惑,但这种解决方案对于多维数组来说似乎并不优雅和有效。

1 个答案:

答案 0 :(得分:0)

从此链接:Compare two arrays and return matches

firstArr = Array("John", "Jacob", "Sam", "Bill")
secondArr = Array("Jen", "Bill", "Mike", "Steve", "John")
dim matchArr()
for i=0 to ubound(firstArr)
    for j=0 to ubound(secondArr)
        if strComp(firstArr(i), secondArr(j), 1)=0 then
           on error resume next
            redim preserve matchArr(ubound(matchArr)+1)
            if err.number<>0 then redim matchArr(0) : err.clear
            on error goto 0
            matchArr(ubound(matchArr))=firstArr(i)
        end if
    next
next
on error resume next
wscript.echo "The number of matches is " & ubound(matchArr)+1
if err.number<>0 then wscript.echo "No match is reported." : err.clear
on error goto 0
'etc etc other stuff