StringReplace
Searches a string for a substring and replaces all found occurrences with a new text.
Syntax
-
StringReplace(s, x, y[, f[, δ]])
-
s
is the string to be searched -
x
is the substring to search for -
y
is the text to changex
to -
f
is a string -
δ
is a positive integer
-
Description
If s
and x
are strings, then StringReplace
searches s
for x
and replaces all found occurrences of x
with y
.
f
specifies flags for the algorithm. It is a string that can contain zero or more of the following characters:
-
i
: MakesStringReplace
search forx
in a case-insensitive manner. -
w
: MakesStringReplace
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, StringReplace
will begin searching s
for x
at character index δ
in s
(the first character having index 1).
Examples
Alice ≔ ExampleData("Alice in Wonderland");
StringReplace(Alice, "Alice", "Harry", "i")
Harry’S ADVENTURES IN WONDERLAND Lewis Carroll THE MILLENNIUM FULCRUM EDITION 3.0 CHAPTER I. Down the Rabbit-Hole Harry was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, ‘and what is the use of a book,’ thought Harry ‘without pictures or conversations?’ So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. There was nothing so VERY remarkable in that; nor did Harry think it so VERY much out of the way to hear the Rabbit say to itself, ‘Oh dear! Oh dear! I shall be late!’ (when she thought it over afterwards, it occurred to her that she ought to have wondered a…