Name
CountStr -- count number of substring occurrences (V4.5)
Synopsis
n = CountStr(s$, sub$[, casesen, startpos, encoding])
Function
This function counts the number of occurrences of sub$ inside s$. The optional argument casesen specifies whether or not the strings shall be compared in a case sensitive manner. Furthermore, you can use the startpos argument to specify an offset into s$ at which CountStr() should start counting. This offset is in characters, not in bytes. Position 0 means the beginning of the string.

The casesen parameter defaults to the global case sensitive default mode set using IgnoreCase(). See IgnoreCase for details.

The optional encoding parameter can be used to set the character encoding to use. This defaults to the default string encoding set using SetDefaultEncoding(). See Character encodings for details.

Inputs
s$
source string
sub$
the string to search in s$
casesen
optional: set this to True if the case in s$ must match the case setting in sub$; the default is True or whatever default has been set using the IgnoreCase() command
startpos
optional: character offset inside s$ to start the search (defaults to 0)
encoding
optional: character encoding to use (defaults to default string encoding) (V7.0)
Results
n
number of occurrences of sub$ inside s$
Example
ret = CountStr("What is that on your head? Is that a new hat? " ..
    "You have not had that on our last chat!", "hat")
The above code should return 6 because "hat" occurs 6 times in the source string.

Show TOC