stringlib::subs -- Substitution in
a string
Introductionstringlib::subs substitutes a substring by another
string.
Call(s)stringlib::subs(string, substring = replacement, <First>)
Parametersstring |
- | non empty string |
substring |
- | non empty string that should be replaced |
replacement |
- | any string that replaced substring |
OptionsFirst |
- | determines, that only the first appearance of
substring in string will be replaced |
Returnsthe given string with substring replaced by
replacement
Related
Functionssubs, stringlib::subsop, stringlib::pos, stringlib::remove
Detailssubstring
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.
Example
1The string replacement may be empty.
>> stringlib::subs("abcdeabcdeabcde", "bc" = "")
"adeadeade"
Example
2Every substring is replaced unless the
option First is given.
>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx")
"axxxdeaxxxdeaxxxde"
>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx", First)
"axxxdeabcdeabcde"
Example
3The substitution may produce a new instance of
substring, but this one is not replaced.
>> stringlib::subs("aab", "ab"="b")
"ab"
string::subs