Jan 30, 2003 #1 EZEason Programmer Dec 11, 2000 213 US How do you search a string to see if part of a work is in it? like: If str1 like "*" & str2 & "*" Then 'what ever you want it to do End if Any Ideas? What doesn't kill you makes you stronger.
How do you search a string to see if part of a work is in it? like: If str1 like "*" & str2 & "*" Then 'what ever you want it to do End if Any Ideas? What doesn't kill you makes you stronger.
Jan 30, 2003 #2 GComyn Programmer Jul 24, 2001 177 US well.. you can use the instr() function.... Code: If instr(1,str1,str2) > 0 Then 'what ever you want it to do End if That way, the if will be true only if str2 is part of str1, and it starts comparing the 2 string at character 1 of str1. GComyn Upvote 0 Downvote
well.. you can use the instr() function.... Code: If instr(1,str1,str2) > 0 Then 'what ever you want it to do End if That way, the if will be true only if str2 is part of str1, and it starts comparing the 2 string at character 1 of str1. GComyn
Jan 30, 2003 #3 pmessana Programmer Jan 24, 2003 19 US Or you can use the Like Operator as follows This example uses the Like operator to compare a string to a pattern. Dim MyCheck MyCheck = "aBBBa" Like "a*a" ' Returns True. MyCheck = "F" Like "[A-Z]" ' Returns True. MyCheck = "F" Like "[!A-Z]" ' Returns False. MyCheck = "a2a" Like "a#a" ' Returns True. MyCheck = "aM5b" Like "a[L-P]#[!c-e]" ' Returns True. MyCheck = "BAT123khg" Like "B?T*" ' Returns True. MyCheck = "CAT123khg" Like "B?T*" ' Returns False. This is straight out of the Access help, they explain it in greater deatil but, you can do yours as follows. MyCheck = str1 like "*str2*" That will return true if str1 ias in str2. Hope that helps. Peter Upvote 0 Downvote
Or you can use the Like Operator as follows This example uses the Like operator to compare a string to a pattern. Dim MyCheck MyCheck = "aBBBa" Like "a*a" ' Returns True. MyCheck = "F" Like "[A-Z]" ' Returns True. MyCheck = "F" Like "[!A-Z]" ' Returns False. MyCheck = "a2a" Like "a#a" ' Returns True. MyCheck = "aM5b" Like "a[L-P]#[!c-e]" ' Returns True. MyCheck = "BAT123khg" Like "B?T*" ' Returns True. MyCheck = "CAT123khg" Like "B?T*" ' Returns False. This is straight out of the Access help, they explain it in greater deatil but, you can do yours as follows. MyCheck = str1 like "*str2*" That will return true if str1 ias in str2. Hope that helps. Peter