简体   繁体   English

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

[英]How to remove duplicates from two dimensional Array in VBS

I have a two dimensional Array which is filled row by row. 我有一个二维数组,它逐行填充。 I got like ~200 entries. 我大约有200个条目。 This is variable but also duplicates are filled. 这是可变的,但也重复填写。

How can i remove those duplicates? 如何删除这些重复项? Or even check if the entries already exist in the Array and skip that duplicate entry? 甚至检查数组中是否已存在条目,然后跳过该重复条目?

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

The question was really interesting that's why a make a try on it.sorry for violating the tag since they ware requested for support in vb script, hope that this will make you think of my concept and make try the same in vb script, my result is as follows. 这个问题真的很有趣,这就是为什么要尝试一下。很抱歉违反标签,因为他们在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

the function will check for duplicates and insert if not exist 该函数将检查重复项,如果不存在则插入

        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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM