2

'我需要能够在 instr 函数中使用两个变量(字符串),但它不会返回正确的值,第一个示例是我需要的样式。但似乎无法让它工作。任何帮助将不胜感激。我已经为此工作了 3 天……它让我充满了愤怒。

    Option Explicit
    dim message, searchTerm, position

     message = "bob dole was here"
     searchTerm = "dole"

     position = InStr(message, searchTerm)
     'This always returns 0


     position = InStr("bob dole was here", searchTerm)
     'This returns 5, which is accurate

     position = InStr(message, "dole")
     'This returns 0,
4

1 回答 1

2

默认情况下,InStr(str1, str2)执行二进制比较。

尝试执行文本比较,如下所示:

position = InStr(1, message, searchTerm, 1)

[我想知道这是否是编码问题。消息字符串来自哪里?]

于 2013-03-07T03:56:47.413 回答