Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何在VB中搜索单词?_Algorithm_Vb6 - Fatal编程技术网

Algorithm 如何在VB中搜索单词?

Algorithm 如何在VB中搜索单词?,algorithm,vb6,Algorithm,Vb6,我已经找到了很多在字符串中查找单词的方法,但是我想做的是找到确切的单词是否存在 例如,如果我搜索test,输入由以下字符串组成:test,testing,测试应用程序,newtest,则程序必须只查找test和测试应用程序,而不查找包含该单词的其他字符串 有人知道怎么做吗?如果可能的话,尤其是在Visual Basic中。您可以使用VB的拆分函数将输入拆分为一个或多个单词数组,然后循环遍历单词,并测试每个单词是否等于“test” 你能展示一下到目前为止你都做了些什么吗?这是VB6还是VB.Net

我已经找到了很多在字符串中查找单词的方法,但是我想做的是找到确切的单词是否存在

例如,如果我搜索test,输入由以下字符串组成:testtesting测试应用程序newtest,则程序必须只查找test测试应用程序,而不查找包含该单词的其他字符串


有人知道怎么做吗?如果可能的话,尤其是在Visual Basic中。

您可以使用VB的拆分函数将输入拆分为一个或多个单词数组,然后循环遍历单词,并测试每个单词是否等于“test”


你能展示一下到目前为止你都做了些什么吗?这是VB6还是VB.Net?@xxbbcc:我可以在大约10个小时内告诉你,现在我在家,我在工作中遇到了这个问题。我没有我现在试过的代码。@salam,
VB.Net
VBA
vb6
。挑一个!你能定义词的界限吗?例如,我怀疑有任何空格,但是像“-”&“,”等符号呢?@hatchet:用于分隔单词的是空格、逗号和点。例如,aa-bb被认为是一个单词
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