|
-
Jul 24th, 2005, 07:10 AM
#1
Thread Starter
Addicted Member
[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.
-
Jul 24th, 2005, 09:37 AM
#2
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|