Can someone please clarify about the InStr command, how it works, an example and will it work with arrays.
Thanks
Printable View
Can someone please clarify about the InStr command, how it works, an example and will it work with arrays.
Thanks
It searches for a string within another string.
What do you mean by work with Array's? If you loop through each element in the array then yes, it will work.Code:Str1 = "This is a string"
Str2 = "is"
If InStr(1, Str1, Str2) > 0 Then MsgBox "Str2 is found in Str1"
what I meant was instead of using str1 in your example, can you use an array?
yes..
like:
Code:
Dim Array1(1) As String
Array1(0) = "This is a String"
Array1(1) = "is"
If InStr(1, Array1(0), Array1(1)) > 0 Then
MsgBox Array1(1) & " is found in " & Array1(0)
Else
MsgBox Array1(1) & " is not found in " & Array1(0)
End If
Code:Dim x&
Dim Arr(1) As String
Arr(0) = "Hello"
Arr(1) = "I'm Jop"
For x = 0 to Ubound(Arr)
if Instr(1, Arr(0), "Jop") then MsgBox "Array " & x & "contains Jop!"
next x