RosettaCodeData/Task/String-matching/QB64/string-matching.qb64

19 lines
638 B
Plaintext

DefStr S
DefInt P
string2 = "dogs"
string1 = "dogs and cats are often enemies,because dogs are stronger than cats, but cats sometimes can be friend to dogs"
position = 0
pcount = 0
Print "Searching "; string2; " into "; string1
While (InStr(position, string1, string2) > 0)
position = InStr(position + 1, string1, string2)
pcount = pcount + 1
If position = 1 Then Print string1; "- starts with -"; string2
Print position
If position = Len(string1) - Len(string2) + 1 Then
Print string1; "- ends with -"; string2
Exit While
End If
Wend
Print string2; " is present "; pcount; " times into "; string1