Hey, i need to count the occurences of a string within a string. I am currently using this:
But it's not working. Could someone please suggest any ideas??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; }
Thanks, much appreciated, BIOSTALL




Reply With Quote