For posterity only, here (not particularly brilliant, but functional) is the way to add any elements my_animalsthat were found in my_string:
Public Sub FindAnimals
dim my_string as String
dim my_animals as Variant
dim found(0) as String
dim animal as String
my_string="MY PETS ARE CAT AND LION"
my_animals=Array ("CAT","DOG","LION")
For Each animal in my_animals
If InStr(my_string, animal) Then
found(UBound(found)) = animal
ReDim Preserve found(UBound(found) + 1)
End If
Next animal
End Sub
Once launched, it foundwill be an array Stringwith three elements:
As I said, this is not the best method the world has ever seen, but it may be the starting point for something better.
source
share