stringlib::subs
-- Substitution in
a stringstringlib::subs
substitutes a substring by another
string.
stringlib::subs(string, substring = replacement, <First>)
string |
- | non empty string |
substring |
- | non empty string that should be replaced |
replacement |
- | any string that replaced substring |
First |
- | determines, that only the first appearance of
substring in string will be replaced |
the given string with substring
replaced by
replacement
subs
, stringlib::subsop
, stringlib::pos
, stringlib::remove
substring
in string
is replaced by replacement
. The
option First causes only the first appearance of
substring
to be replaced.substring
. See Example 3.substring
,
the leftmost one is replaced.The string replacement
may be empty.
>> stringlib::subs("abcdeabcdeabcde", "bc" = "")
"adeadeade"
Every substring
is replaced unless the
option First
is given.
>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx")
"axxxdeaxxxdeaxxxde"
>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx", First)
"axxxdeabcdeabcde"
The substitution may produce a new instance of
substring
, but this one is not replaced.
>> stringlib::subs("aab", "ab"="b")
"ab"
string::subs