Arrays 在Visual Basic中检查数组中的任何项是否与另一个数组中的任何项匹配
我有一个目录,里面有.txt文件。我正在将每个文件的行写入一个数组,需要知道一个文件中的任何行是否与另一个文件中的任何行匹配 示例:Arrays 在Visual Basic中检查数组中的任何项是否与另一个数组中的任何项匹配,arrays,vb.net,visual-studio,Arrays,Vb.net,Visual Studio,我有一个目录,里面有.txt文件。我正在将每个文件的行写入一个数组,需要知道一个文件中的任何行是否与另一个文件中的任何行匹配 示例: If any item in Array1 = any item in Array2 then... For Each foundBaseFile As String In My.Computer.FileSystem.GetFiles _ (DataDir, _ FileIO.SearchOption.SearchTopLevelOnly, "*.
If any item in Array1 = any item in Array2 then...
For Each foundBaseFile As String In My.Computer.FileSystem.GetFiles _
(DataDir, _
FileIO.SearchOption.SearchTopLevelOnly, "*.vpk.txt")
Dim BaseTextArray = IO.File.ReadAllLines(foundBaseFile)
For Each foundCheckFile As String In My.Computer.FileSystem.GetFiles _
(DataDir, _
FileIO.SearchOption.SearchTopLevelOnly, "*.vpk.txt")
If Not foundBaseFile = foundCheckFile Then
Dim CheckTextArray = IO.File.ReadAllLines(foundCheckFile)
'If any item in CheckTextArray = any item in BaseTextArray then
' Do X
'End If
End If
Next
Next
迄今为止的代码:
If any item in Array1 = any item in Array2 then...
For Each foundBaseFile As String In My.Computer.FileSystem.GetFiles _
(DataDir, _
FileIO.SearchOption.SearchTopLevelOnly, "*.vpk.txt")
Dim BaseTextArray = IO.File.ReadAllLines(foundBaseFile)
For Each foundCheckFile As String In My.Computer.FileSystem.GetFiles _
(DataDir, _
FileIO.SearchOption.SearchTopLevelOnly, "*.vpk.txt")
If Not foundBaseFile = foundCheckFile Then
Dim CheckTextArray = IO.File.ReadAllLines(foundCheckFile)
'If any item in CheckTextArray = any item in BaseTextArray then
' Do X
'End If
End If
Next
Next
谢谢 这应该能奏效
If BaseTextArray.Any(Function(o) CheckTextArray.Contains(o)) Then
' Do X
声明两个数组变量
dim arr1() as string
dim arr2() as string
从.txt文件第b行读取值并添加到每个arrarlevel。也可以按vbnewline分割线
然后使用
Array.Indexof()
方法来查找第一个数组字符串中的值是否存在于其他数组字符串中
If indx >1 then
True
Else
False
end if