StringTools
Subs
effect multiple substitutions in a string
Calling Sequence
Parameters
Description
Examples
Compatibility
Subs( [ L1 = R1, L2 = R2, ... ], s )
Subs( { L1 = R1, L2 = R2, ... ], s )
Subs( L = R, s )
s
-
string; the string in which to effect substitutions
L, L1, L2, ...
string; left hand sides of substitutions; substrings to replace
R, R1, R2, ...
string; right hand sides of substitutions; replacements for corresponding left hand sides
The Subs command effects (single or) multiple substitutions in a string s as specified by its first argument. The precise way in which those substitutions take place depends upon the form of the first argument, which may be a single equation of the form L = R, or a set or list of such equations.
If the first argument is a single equation L = R, then Subs( L = R, s ) simply replaces occurrences of the substring L in s by the string R, by using the command StringTools:-SubstituteAll( s, L, R ).
When a list of substitutions is presented as the first argument, then the substitutions in the list are performed serially, in the order specified. This means that the first substitution L1 = R1 is applied to the string s, using the command StringTools:-SubstituteAll( s, L1, R1 ). Then, the substitution L2 = R2 is applied to the result; then the substitution L3 = R3 is applied to the result of that, and so on.
When the substitutions are given as a set, then parallel substitutions are effected, with the "longest-match rule" being used to resolve multiple matches in the input string s. This means that, if two of the left hand sides among L1, L2, ... match a substring of s at the same position, then the longest such match is used in the substitutions.
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
Subs⁡ab=XY,uvabbaabcst
uvXYbaXYcst
Note the difference between serial and parallel substitutions
Subs⁡ab=XY,abc=QRST,uvabbaabcst
uvXYbaQRSTst
The following example illustrates the significance of the order of substitutions in a list.
Subs⁡Yc=FOO,ab=XY,abc=QRST,uvabbaabcst
Subs⁡ab=XY,abc=QRST,Yc=FOO,uvabbaabcst
uvXYbaXFOOst
The StringTools[Subs] command was introduced in Maple 2017.
For more information on Maple 2017 changes, see Updates in Maple 2017.
See Also
string
StringTools[SearchAll]
StringTools[SubstituteAll]
Download Help Document