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



我有一个二维数组,它是逐行填充的。我收到了大约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

这个问题真的很有趣,这就是为什么我要试一试。很抱歉违反了标签,因为他们被要求在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

相关内容

  • 没有找到相关文章

最新更新