StringCount
Counts the number of times a given substring occurs in a string.
Syntax
-
StringCount(s, x[, f[, δ]])-
sis the string to be searched -
xis the substring to search for -
fis 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: MakesStringCountsearch forxin a case-insensitive manner. -
w: MakesStringCountonly considerxto be a substring ofsifxis 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