<substitute>
<substitute>
is a General Operator
component that replaces one character or
string from a math or a text with another specified string.
Note that substitution is used for variables in math expressions, not numerical values. Doenet ignores requests for substitution of strict numerical values in math expressions.
Attributes and Properties
Attribute | Type | Values |
---|---|---|
assignNames = "…" | ||
assignNamesSkip = "…" | ||
displayDecimals = "…" | integer | |
displayDigits = "…" | integer | |
displaySmallAsZero = "…" | number | |
match = "…" | ||
matchCase = "…" | boolean | "true" "false" |
matchWholeWord = "…" | boolean | "true" "false" |
padZeros = "…" | boolean | "true" "false" |
preserveCase = "…" | boolean | "true" "false" |
replacement = "…" | ||
simplify = "…" | text | "none" "full" "numbers" "numberspreserveorder" |
type = "…" | text | "math" "text" |
Property | Type |
---|---|
$s.displayDecimals | integer |
$s.displayDigits | integer |
$s.displaySmallAsZero | number |
$s.matchCase | boolean |
$s.matchWholeWord | boolean |
$s.padZeros | boolean |
$s.preserveCase | boolean |
$s.simplify | text |
$s.type | text |
Example: substitute a different variable in a math
In this example, the <substitute>
component is used to swap out one variable from a user-input expression for another. Two attributes are required:
match
, which defines the content to replacereplacement
, which defines the new content
The default type for substitution is math.
The substititution is performed in a <setup>
block, which does not render on the page. The modified expression is later rendered by referencing the name of the <substitute>
component in line with $sub
.
Example: Replace one word with another in a text string
In this example, the <substitute>
component is used to swap out one word from a user’s <textInput>
for another. The type = "text"
specification is made for the <substitute>
component; this is required as the default type
is math.
The substititution is performed in a <setup>
block, which does not render on the page. The modified text is later rendered by referencing the name of the <substitute>
component in line with $sub
.
Example: substitute a user-provided value in a math
In this example, the user provides the substituted value in the math expression.
Example: type
The default substitution type is math
. Use type="text"
to switch the type of substitution to text.
Example: match, replacement
The match
attribute specifies content to be replaced with the <substitution>
component.
The replacement
attribute specifies new content to be inserted with the <substitution>
component.
Example: simplify
The <substitution>
component accepts the standard simplify
attribute for math components.
Example: matchWholeWord
By default, Doenet separates strings into individual, case-insensitive characters when finding matches for substitution. If a strict match of the entire word is desired, use the the matchWholeWord
attribute
Example: matchCase
By default, matching is case-insensitive with the <substitution>
component. Use matchCase
to change this default behavior.
Example: preserveCase
To preserve the case of the letter in the original text string, use the preserveCase
attribute.