Results 1 to 6 of 6

Thread: Another String question

  1. #1

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    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?
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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")
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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")

  4. #4
    Junior Member
    Join Date
    May 2000
    Location
    Alaska
    Posts
    21

    Or you can write something to anti-TesticleMole virus.

    MsgBox Replace("Batman is moron!", "moron", "the COOLEST person on this bat earth")
    Alaska

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yeah, that would be a great project, let's start coding an Antivirus *g*

    btw: Batman, we want you back!!!

  6. #6

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    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.
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width