Results 1 to 5 of 5

Thread: counting instance of a string in a string

  1. #1

    Thread Starter
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    In VbScript (ASP usage), can anyone tell me how i would check to see how many times a string occurs in another string?

    Thanks for your time, patience, and money.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Code:
    <%@ Language=VBScript %>
    <%option explicit%>
    <HTML>
    
    <BODY>
    <%
    	
    dim strTemp
    strTemp =  "big bad pig big hod bad door fig"
    response.write strTemp & "<BR>"
    
    response.write oc(strTemp,"bad")
    
    
    
    Function oc(strIn, strTest)
    Dim i
    Dim j
    Dim l 
    l = Len(strTest)
    
    i = InStr(strIn, strTest)
    While i > 0
      j = j + 1
      strIn = Mid(strIn, i + l)
      
      i = InStr(strIn, strTest)
    Wend
    
    oc = j
    
    End Function
    
    
    
    %>
      
    </BODY>
    </HTML>
    Mark
    -------------------

  3. #3
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Changing Marks code..
    to a simpler way...

    <%@ Language=VBScript %>
    <%option explicit%>
    <HTML>

    <BODY>
    <%

    dim strTemp,myArray
    strTemp = "big bad pig big hod bad door fig"
    response.write strTemp & "<BR>"
    myArray = Split(strTemp,"bad",-1,1)
    response.write Ubound(myArray)
    %>

    </BODY>
    </HTML>
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Thumbs up

    That's neat Active!
    Mark
    -------------------

  5. #5

    Thread Starter
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    you guys rule. thanks a lot!

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