|
Calling Sequence
|
|
Subs( [ L1 = R1, L2 = R2, ... ], s )
Subs( { L1 = R1, L2 = R2, ... ], s )
Subs( L = R, s )
|
|
Parameters
|
|
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
|
|
|
|
|
Description
|
|
•
|
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 -bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
|
|
|
Examples
|
|
Note the difference between serial and parallel substitutions
The following example illustrates the significance of the order of substitutions in a list.
|
|
Compatibility
|
|
•
|
The StringTools[Subs] command was introduced in Maple 2017.
|
|
|
|