Assuming your lookup table is rather static (may be reloaded occasionally but not for every comparison), you can try something like this. I also assumed you like the strings to be compared case insensitively (otherwise remove the lines that call .ToLowerInvariant()
).
StartUp.vb:
(Provides a property with the lookup table and a method to reload it.)
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows.Forms
Module StartUp
<STAThread>
Sub Main(args As String())
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New MainForm())
End Sub
Private _LookupTable As Dictionary(Of String, String)
Public ReadOnly Property LookupTable As Dictionary(Of String, String)
Get
Dim myResult As Dictionary(Of String, String) = _LookupTable
If (myResult Is Nothing) Then
myResult = New Dictionary(Of String, String)(StringComparer.Ordinal)
Const myFilePath As String = "C:\Temp\Foo.txt"
For Each myLine As String In File.ReadAllLines(myFilePath)
'Ignore leading and tailing white-space as well as empty lines
myLine = myLine.Trim()
If (myLine.Length = 0) Then Continue For
'Apply some optimizations
Dim myLineLC As String = myLine.Normalize()
myLineLC = myLineLC.ToLowerInvariant()
myLineLC = myLineLC.Normalize()
myLineLC = String.Intern(myLineLC)
'Add the line to the dictionary (we like to ignore duplicates, therefore we don't use Add() which would throw an exception is such a case)
myResult(myLineLC) = myLine
Next
_LookupTable = myResult
End If
Return myResult
End Get
End Property
Public Sub ReloadLookupTable()
_LookupTable = Nothing
End Sub
End Module
MainForm.vb: (Provides an event handler for an OK-button as well as a function to lookup which lines match the strings in the lookup table)
Imports System
Imports System.Collections.Generic
Public Class MainForm
Private Sub btnOkay_Click(sender As Object, e As EventArgs) Handles btnOkay.Click
Dim myLines As String() = TextBox1.Lines
For Each myFound As String In LookupLines(myLines)
'do something with the found strings
Next
End Sub
Private Iterator Function LookupLines(lines As IEnumerable(Of String)) As IEnumerable(Of String)
If (lines Is Nothing) Then Throw New ArgumentNullException(NameOf(lines))
Dim myLookupTable As Dictionary(Of String, String) = LookupTable
For Each myLine As String In lines
'Ignore leading and tailing white-space as well as empty lines
myLine = myLine.Trim()
If (myLine.Length = 0) Then Continue For
'Apply some optimizations
myLine = myLine.ToLowerInvariant() 'like this we avoid IgnoreCase comparison
myLine = myLine.Normalize() 'like this we can use Ordinal comparison instead of InvariantCulture one.
myLine = String.Intern(myLine) 'like this two same strings return the same reference which is exceptionally fast to compare
'Check whether the dictionary contains the line
Dim myResult As String = Nothing
If (myLookupTable.TryGetValue(myLine, myResult)) Then Yield myResult
Next
End Function
End Class