[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
Re: Counting the occurences of a string within a string
Whoops, sorry, i've sorted it. I used the split() function