我找到了很多用于在字符串中查找单词的方法,但我想用它来查找确切的单词是否存在。
例如,如果我搜索测试并且输入由字符串组成:测试,测试,测试应用程序, newtest ,该程序必须只找到测试和测试应用程序,而不是包含该单词的其他文件。
有人知道怎么做吗?特别是在Visual Basic中。如果可能的话。
答案 0 :(得分:0)
您可以使用VB的Split函数将输入拆分为单词数组(或数组),然后遍历单词并测试每个单词是否等于“test”。
Sub test()
Dim sInput As String
sInput = "test, testing, a test application, newtest"
arInput = Split(sInput, ",")
Dim cMatched As New Collection
For Each sPhrase In arInput
arWords = Split(sPhrase, " ")
bMatched = False
For Each sword In arWords
If sword = "test" Then bMatched = True
Next
If bMatched Then
cMatched.Add sPhrase
MsgBox sPhrase
End If
Next
End Sub