'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,
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?]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.