Replace Command
Obsolete
This command is replaced by the Replace function.
Purpose
To search a string for a substring, and if the substring is present, to replace the first occurrence of the substring with a different substring.
Syntax
replace
oldSubstring
in
hostString
with
newSubstring
Argument Explanation
- hostString: May be of any class except constant or expression.
What It Does
The replace command scans hostString for oldSubstring. If oldSubstring is found in hostString, it is removed, and newSubstring is inserted into hostString. The predefined indicator found is set to true, and the position at which oldSubstring began is moved to the predefined variable strmark. If oldSubstring is not found, no deletion or insertion occurs, found is set to false, and zero is moved to the predefined variable strmark.
Example
string park
move "Everglades National Park" to park
replace "Everglades" in park with "Yellowstone"
In this example, the string variable park is searched for the substring Everglades. When Everglades is found (at the beginning in this case), it is removed, and the word Yellowstone is inserted in its place.
The replace command sets the value of the predefined variable strmark, which is used by the mid and right commands when those commands omit a position specification. This is intended to facilitate implicit positioning, illustrated by the following example:
string alpha_suffix
replace "A" in "123ABC" with "Z"
[found] right "123ZBC" to alpha_suffix
In this example, the replace command places a value of 4 (the position of A in 123ABC) in strmark. The succeeding right command will use 4 as the position specification and move the substring (ZBC) beginning at that position to the string variable alpha_suffix. The action would be defeated if the right command had a position specifier.
If you wish to simply remove a substring from a hostString, replace it with "" (two quotation marks).
Notes
- The
replacecommand is case-sensitive. Thus, the followingnewSubstringwould not be executed, andfoundis set to false:
replace "DEF" in "abcdefgh" with "xyz"