How many characters in a string using javascript

I need to find out how many specific characters are in the string… I have tried a few things but none are working.

thisdoc = document.forms[0];

thisdoc.StringAnwsers.value // this string contains ~abcd~sftg~wert~tutu~

I just need to know how many ~ are in the string…

alert(thisdoc.write(StringAnwsers.value.indexOf(‘~’)));

any ideas anyone ?

thanks

Paul

Subject: how many characters in a string using javascript

count = 0;pos = str.indexOf(“~”);

while ( pos != -1 ) {

count++;

pos = str.indexOf(“~”,pos+1);

}

Ok - I just Googled “Javascript String Count Occurrences”. :wink:

Subject: RE: how many characters in a string using javascript

This is the error I get when using the indexOf…

Error: Object doesn’t support this property or method

Subject: RE: how many characters in a string using javascript

Is ‘str’ properly Dimmed as a string?

Subject: RE: how many characters in a string using javascript

Working fine now…Thanks a bunch!