$count

From Scriptwiki
Revision as of 03:36, 23 July 2006 by Albie (talk | contribs) (New article)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Returns the number of times a substring occurs in a string.

$count(<haystack>,<needle>[,needle2,...,needleN])

Examples

$count returns the total occurances of all needles found in the haystack.

var %haystack = I bought six apples and three pears. I ate one apple and threw the another Apple at Dana.
echo -ag I found $count(%haystack,apple) apple(s).
echo -ag I found $count(%haystack,pear) pear(s).
echo -ag I found $count(%haystack,apple,pear) apple and pear(s).
echo -ag I found $countcs(%haystack,Apple) case sensitive Apple(s).
echo -ag I found $countcs(%haystack,Pear) case sensitive Pear(s).

Result:
I found 3 apple(s).
I found 1 pear(s).
I found 4 apple and pear(s).
I found 1 case sensitive Apple(s).
I found 0 case sensitive Pear(s).

Note

$countcs is a case sensitive version of $count