Results 1 to 2 of 2

Thread: [RESOLVED] Counting the occurences of a string within a string

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Resolved [RESOLVED] Counting the occurences of a string within a string

    Hey, i need to count the occurences of a string within a string. I am currently using this:

    Code:
    var bcount=0;
    var bccount=0;
    
    pos = str.indexOf("[bold]");
      while ( pos != -1 ) {
         bcount++;
         pos = str.indexOf("[bold]",pos+1);
      }
     pos = str.indexOf("[/bold]");
      while ( pos != -1 ) {
         bccount++;
         pos = str.indexOf("[/bold]",pos+1);
      }
     if (bcount>bccount) {
      alert("You have more opening 'Bold' tags than closing 'Bold' tags");
      return false;
     }
     if (bcount<bccount) {
      alert("You have more closing 'Bold' tags than opening 'Bold' tags");
      return false;
     }
    But it's not working. Could someone please suggest any ideas??

    Thanks, much appreciated, BIOSTALL
    Last edited by BIOSTALL; Jul 24th, 2005 at 09:37 AM.

  2. #2

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: Counting the occurences of a string within a string

    Whoops, sorry, i've sorted it. I used the split() function

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