The number of occurances of a string within anothe

Results 1 to 2 of 2

Thread: The number of occurances of a string within anothe

  1. #1
    Chad Franklin Guest

    Default The number of occurances of a string within anothe

    I need to create code that will allow me to COUNT the number of occurances of a string within another string?<BR><BR>String1 = "abc1def1"<BR>String2 = "1"<BR><BR>The answer will be 2<BR><BR>I want to find out the number of String1&#039s in String2.<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    66

    Default RE: The number of occurances of a string within an

    Function Occurences(sStringToSearch, sStringToFind)<BR><BR> Dim nFound<BR> dim nLastFoundAt<BR> <BR> nFound = 0<BR> nLastFoundAt = 1<BR><BR> Do<BR><BR> nReturn = instr(nLastFoundAt, sStringToSearch, sStringToFind)<BR><BR> if nreturn &#060; 1 then <BR> exit do<BR> end if<BR><BR> nFound = nFound + 1<BR> nLastFoundAt = nReturn + 1<BR><BR> Loop<BR><BR> Occurences = nFound<BR>End Function<BR><BR>Call it as &#060;%=Occurences("abc1def1", "1")%&#062;<BR><BR>HTH

Posting Permissions

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