StringCount
Counts the number of times a given substring occurs in a string.
Syntax
-
StringCount(s, x[, f[, δ]])
-
s
is the string to be searched -
x
is the substring to search for -
f
is a string -
δ
is a positive integer
-
Description
If s
and x
are strings, then StringCount
returns the number of times x
occurs in s
, subject to any additional restrictions imposed by the remaining arguments.
f
specifies flags for the algorithm. It is a string that can contain zero or more of the following characters:
-
i
: MakesStringCount
search forx
in a case-insensitive manner. -
w
: MakesStringCount
only considerx
to be a substring ofs
ifx
is found as a full word ins
.
If omitted, f
defaults to ""
(no options).
Finally, if δ
is specified, StringCount
will begin searching s
for x
at character index δ
in s
(the first character having index 1).
Examples
Alice ≔ ExampleData("Alice in Wonderland");
'("rabbit", "beautiful", "extraordinary", "mirror") @ (word ↦ StringCount(Alice, word, "i"))
52 15 2 0