StringIndices
Returns a list with the positions of all occurrences of a given substring in a string.
Syntax
-
StringIndices(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 StringIndices
returns the list with the positions of all occurrences of x
in s
, subject to any additional restrictions imposed by the remaining arguments. The list is sorted.
f
specifies flags for the algorithm. It is a string that can contain zero or more of the following characters:
-
i
: MakesStringIndices
search forx
in a case-insensitive manner. -
w
: MakesStringIndices
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, StringIndices
will begin searching s
for x
at character index δ
in s
(the first character having index 1).
Examples
Alice ≔ ExampleData("Alice in Wonderland");
StringIndices(Alice, "rabbit", "i") \ 10
118 696 850 1069 1260 1455 1605 5390 5675 13749 ⋮