I'd like the quickest way (in excel VBA) to identify whether one string occurs anywhere within another - an 'includes' function perhaps?
views:
174answers:
2
+13
A:
I believe INSTR() is the function; if it returns anything other than zero, the string is found.
exists = InStr("avbprogram", "vb") <> 0
Carl Manaster
2009-07-08 17:34:36
Beat me to it :P
MitMaro
2009-07-08 17:36:00
+8
A:
Carl is correct but you should also know that the default compare option for InStr is case-sensitive. If you want to do case-insensitive checks you should either wrap your arguments in LCase/UCase or use the extended form of the InStr function as shown below:
exists = InStr(1, "avbprogram", "vb", vbTextCompare)
where the first argument is the index of the first character to start comparing from and the last argument indicates case-insensitive comparison. The short-hand that Carl showed is actually equivalent to what is shown below:
exists = InStr(1, "avbprogram", "vb", vbBinaryCompare)
tchester
2009-07-08 17:44:18