检查字符串数组和列表框是否有任何相似之处

时间:2017-08-21 01:18:09

标签: vb.net

标题说明了一切,我一直试图弄清楚如何检查列表框和字符串数组是否有任何相同且不成功的条目。

Module Module1
    Public detectedMD5 As String() = {"944a1e869969dd8a4b64ca5e6ebc209a"}
End Module

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim procs() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
    Dim f As String

    For Each proc As Process In procs
        f = GetProcessFileName(proc)
        If f.Length > 0 Then
            ListBox1.Items.Add(GetMD5String(f))
        End If
    Next

    'Here is where I have been trying to compare the detectedMD5 string array to the listbox

End Sub

我确实尝试过像

这样的事情
    Do
        Try
            i = i + 1
            ListBox1.SelectedIndex = i
            Dim detection As String
            For Each item As String In detectedMD5
                detection = InStr(ListBox1.SelectedItem, item)
                If detection > 0 Then
                    MsgBox("Detected")
                End If
            Next
        Catch
            i = -1
            ListBox1.Items.Clear()
            Exit Do
        End Try
    Loop

但那不起作用,而且

 Exception thrown: 'System.ArgumentOutOfRangeException' in System.Windows.Forms.dll

1 个答案:

答案 0 :(得分:0)

它给出InvalidCastException错误的原因是因为您需要将ListBox.Items强制转换为String。

Dim intersection = detectedMD5.Intersect(ListBox1.items.Cast(Of String))