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

14,385

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?]

Share:
14,385
zyther
Author by

zyther

Updated on June 04, 2022

Comments

  • zyther
    zyther almost 2 years

    '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,
    
  • zyther
    zyther about 11 years
    that worked. funny how a simple 1 can change the entire thing. thank you for your help ive been working on this for far too long.