This function works just like the Search function in notepad, it will search a string and either return the position in the string it found what you searched for or return the number of times it found it.
You can search for an exact case match if you want.
- Enjoy
Function StringSearch(SearchString$,InputString$,MatchCase,FindAll)
`--------------------------------------------------------------------------
`This function searches InputString$ to see if SearchString$ can be found
`InputString$ is the text you want to search in
`SearchString$ is the text you want to find in InputString$
`If it finds it then the function returns the position at which it found it
`You can set MatchCase to 1 if you want an exact case match
`If FindAll is set to 1 then StringSearch will return the number of times
`it found the searchstring
`The function returns zero if it couldnt find the searchstring
`--------------------------------------------------------------------------
If MatchCase=0 `If MatchCase=0 then convert the inputstring and searchstring to lowercase
SearchString$=Lower$(SearchString$)
InputString$=Lower$(InputString$)
EndIf
I=0
PosFound=0
Do
If Left$(Right$(InputString$,Len(InputString$)-I),Len(SearchString$))=SearchString$
If FindAll=1
Inc PosFound,1
else
PosFound=I+1
Exit
EndIf
EndIf
If I<Len(InputString$) then Inc I,1 else Exit
Loop
EndFunction PosFound
And and example of how to use it:
Print "String found "+Str$(StringSearch("zebra","The big black zebra named John was jumping about",0,1))+" times"
Print "Press a key..."
Wait Key