Using JavaScript:
What is the function that I can use to calculate how many string found in the string..
if Text="how are you . I hope you are fine"
I want to know how many (are) string in this string
output Here:
2
Printable View
Using JavaScript:
What is the function that I can use to calculate how many string found in the string..
if Text="how are you . I hope you are fine"
I want to know how many (are) string in this string
output Here:
2
Code:function GetOccurances(str){
var m = /are/g; //word to find RegExp
var oStr = new String(str);
if( oStr.search(m) > -1){ //at least on occurance
var array = oStr.match(m);
return array.length
}
return 0;
}
But try this code:
[CODE]
<Script language=JavaScript>
function GetOccurances(str,Find)
{
var m =RegExp (Find,"gi");
var oStr = new String(str);
var No = oStr.match(m);
return No.length
return Find
}
X=GetOccurances("hor [CODE] [CODE] ARE [CODE] you are hi are","Code:");
document.write (X);
</Script>
When I calculate (Code) word it give me right output but when I calculate [CODE] or any word contain [ and ] it give me error output .... Why ? How can I solve this problem