Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strInput LIKE strText ???? LIKE doesn't work 1

Status
Not open for further replies.

Rexolio

Technical User
Aug 29, 2001
230
0
0
I have 2 fields where a user puts in the data. On the next page I retrieve that data:

strInput = Request.form("Input")
strText = Request.form("Text")

I need to see if strText contains any part of strInput, but not sure how to do this. If I were connecting to a database, I'd simply put

SQL="Select * where Text LIKE '%Input%'"

but obviously that doesn't work in this case. What can I do?
 
Use Instr function (Works in VB script only).

Syntax

InStr([start, ]string1, string2[, compare])

where string1 is the string in which string2 has to be searched.
 
INSTR(1,"HELLO","O",1)
This will return the value 5 (as the letter O is the 5th carakter of HELLO.
INSTR(1,"HELLO","o",1)
This will return the value 5 because the last 1 means text compare (not case sensitive).
INSTR(1,"HELLO","no",1)
Tis will return 0 because no is not in HELLO.

To check your 2 strings use:
if INSTR(1,strText ,strInput ,1) > 0
' strInput is part of strText
else
' strInput is not part of strText.
end if
 
Thanks, harmmeijer...works like a charm!
 
Btw, if you ever do any VB programming, there IS a LIKE operator there that works like it does in SQL (except the "anything" wildcard character is an asterisk instead of a percent sign). The new ASP.NET, which is much more VB-like, has this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top