04-29-2025, 11:17 PM
Hi
taken from wiki INSTR example,
taken from wiki INSTR example,

Code: (Select All)
_Title "Find recurrence and position of a substring in a string"
Dim text$, Searched$, Count%
ReDim Where%(1 To 1)
text$ = "The cats and dogs where playing, even though dogs don't like cats."
Searched$ = "cats"
Print "Founded: "; Find(Count%, Where%(), text$, Searched$); Count%; " times"
For see% = 1 To Count% Step 1
Print Where%(see%)
Next see%
End
Function Find (Count%, Where%(), Text$, Searched$)
Dim findS%
Count% = 0
Find = 0
If Len(Text$) = 0 Or Len(Searched$) = 0 Then Exit Function
Do
findS% = InStr(findS% + 1, Text$, Searched$) ' find another occurance after
If findS% Then
Count% = Count% + 1
ReDim _Preserve Where%(1 To Count%)
Where%(Count%) = findS%
End If
Loop Until findS% = 0
If Count% > 0 Then Find = -1
End Function