答案 0 :(得分:0)
这是一个相当简单的解决方案。请注意,它会在“四”中找到“我们的”一词。如果这不合适,你可以写一些东西来消除重叠的匹配。
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim SearchText As String = "One Two Three Four"
Dim Keywords As String() = {"One", "Four", "our"}
Dim WordMatches As New Generic.List(Of WordMatch)
For Each KeyWord As String In Keywords
Dim i As Int32 = 0
While i <> -1
i = SearchText.IndexOf(KeyWord, i, System.StringComparison.OrdinalIgnoreCase)
If i <> -1 Then
Dim MyMatch As New WordMatch
MyMatch.CharIndex = i
MyMatch.Word = KeyWord
WordMatches.Add(MyMatch)
i += KeyWord.Length
End If
End While
Next
End Sub
Private Structure WordMatch
Public CharIndex As Int32
Public Word As String
End Structure