I need to know how many times a string sows up in a larger string, i.e.:
How many times does "bat" show up in
"That's bat cool batman, how bat are you?"
Anyone know?
Printable View
I need to know how many times a string sows up in a larger string, i.e.:
How many times does "bat" show up in
"That's bat cool batman, how bat are you?"
Anyone know?
Code:Function wordcount(txt$, search
Dim pos As Long
If Len(txt) = 0 Then Exit Function
pos = InStr(txt, search)
Do Until pos = 0
wordcount = wordcount + 1
pos = InStr(pos + 1, txt, search)
Loop
End Function
'Usage
Msgbox wordcount (text1, "bat")
Just an idea, not tested:
Code:Dim Count as Long
Dim Temp as Long
Temp = 1
While Temp <> 0
Temp = InStr( Temp, YourText, "bat" )
if Temp > 0 Then
Temp = Temp + 1
Count = Count + 1
Endif
Wend
MsgBox "Found it " & CStr(Count) & " time" & IIf(Count = 1, "", "s")
MsgBox Replace("Batman is moron!", "moron", "the COOLEST person on this bat earth")
Yeah, that would be a great project, let's start coding an Antivirus *g*
btw: Batman, we want you back!!!
Thanks guys, you've been really helpful. I'll be sure to mention you in my credits. BTW, the program I'm making will probably end up sucking, so if anyone's interested, when I'm finished, I'll let you tinker with it to see if anyone has any design ideas.