>

How to count the no of phrases in the given string

vbscript

1.How can we count the no of ‘the’ phrases in the given string that is “the good + the bad & the ugly”

There are 2 ways which you can easily get the answer.

a.stringtext=”the good + the bad & the ugly”
strsearch=split(stringtext,”the”)
searchcount=ubound(strsearch)
msgbox searchcount (this will give the count of no of times “the” appears in the string

b.stringtext=”the good + the bad & the ugly”
stringtext=”the good + the bad & the ugly”
strsearch=”the”
‘Replace “the”  text with “”
reptext=replace(stringtext,”the”,””)
‘suntract the difference and then divide by the length of the string to be searched”
strcount=(len(stringtext)-len(reptext))/len(strsearch)
msgbox strcount

Leave a Reply