zyther
zyther

Reputation: 53

How to use 2 variables in vbscript for InStr Function in VBScript

'I need to be able to use two variables, (strings) in the instr function but it will not return proper values, the first example is the style i need. but cant seem to get it to work. any help would be greatly appreciated. ive been working on this for 3 days..its filling me with rage.

    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,

Upvotes: 2

Views: 14677

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300579

By default, InStr(str1, str2) performs a binary comparison.

Try performing a textual comparison, like so:

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

[I wondering if it is an encoding issue. Where is the message string coming from?]

Upvotes: 2

Related Questions