如何从VBS中的二维数组中删除重复项

时间:2014-07-18 09:27:11

标签: arrays multidimensional-array vbscript duplicates

我有一个二维数组,逐行填充。我有~200个条目。这是可变的,但也填充了重复。

如何删除这些重复项?或者甚至检查数组中是否已存在条目并跳过该重复条目?

for each oSingleNode in oNodeList
    if oSingleNode.xml <> "" Then
          Set oNode = oSingleNode.selectSingleNode("j.8:entity-reference")
          if not oNode is nothing then
              s =  oNode.getAttribute("rdf:resource")
              a = Split(s, "/")
              attribute = a(ubound (a)-1)
              Set oNodeTwo = oSingleNode.selectSingleNode("j.8:entity-label")
              if not oNodeTwo is nothing then
              label = oNodeTwo.text
              array(rowIndex,index) = attribute
              array(rowIndex,constClm)= label
              debug2File array(rowIndex,index) & " " & array (rowIndex, constClm)                         
          End if            
     End if  
End If

1 个答案:

答案 0 :(得分:0)

问题非常有趣,这就是为什么要试一试it.sorry因为他们要求vb脚本中的支持而违反标签,希望这会让你想到我的概念并在vb脚本中尝试相同,我的结果如下。

 Dim a(10, 10), i, j As Integer
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 j += 1
 If j > 10 Then
 i += 1
 j = 0
 End If
 check_val(CInt(TextBox1.Text), i, j)
 End Sub

该函数将检查重复项并插入(如果不存在)

        Public Sub check_val(ByVal x As Integer, ByVal i As Integer, ByVal j As Integer)
        Dim t As Integer = 0
        For k As Integer = 0 To 10
        For l As Integer = 0 To 10
        If x = a(k, l) Then
        t = 1
        End If
        Next
        Next
        If t = 0 Then
        a(i, j) = x
        Else
        MsgBox("Repeting value")
        j = j - 1
        End If
        End Sub