Replace()
Replace every occurrence of a substring with another.
also: replace substitute swap text find and replace change all rename substitute swap change find and replace put instead
The forms of this verb
Replace · Replaced
Basic examples (2)
# Q(@char).IsNotLetter() targets the symbols, leaving spaced words
? Q("ABC♥DEF★GHI♥JKL").ReplaceWQ('Q(@char).IsNotLetter()', :With = " ").Content()ABC DEF GHI JKL
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 395_replacew.ring(opens in a new tab)
o1 = new stzString("R I N G")
o1.Replace(" ", "-")
# Replace() mutates the object
? o1.Content()R-I-N-G
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 55_replace_ref_vs_copy.ring(opens in a new tab)
Scope (8)
o1 = new stzString("a + b - c / d = 0")
o1.ReplaceMany([ "+", "-", "/" ], "*")
# all become *
? o1.Content()a * b * c * d = 0
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 792_content.ring(opens in a new tab)
o1 = new stzString(" isNumber( 0+ @item ) ")
o1.ReplaceMany([ "" ], 'any')
# the content is unchanged
? o1.Content()isNumber( 0+ @item )
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 261_content.ring(opens in a new tab)
o1 = new stzString("~♥/♥\~~")
o1.ReplaceXT("♥", :At = 2, :With = "~")
# the heart at position 2 becomes '~'
? o1.Content()~~/♥\~~
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 192_replacext_at.ring(opens in a new tab)
o1 = new stzString("one two three four")
o1.ReplaceMany([ "two", "four" ], :By = "---")
# both became dashes
? o1.Content()one --- three ---
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 694_content.ring(opens in a new tab)
o1 = new stzString("_♥♥\__/♥\__/♥\_")
o1.ReplaceXT(:First, "♥", :With = "/")
# the first heart becomes a slash
? o1.Content()_/♥\__/♥\__/♥\_
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 190_replacext_first.ring(opens in a new tab)
o1 = new stzString("a + b - c / d = 0")
o1.ReplaceMany([ "+", "-", "/" ], :By = "*")
# +, - and / all become *
? o1.Content()a * b * c * d = 0
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 57_replacemany.ring(opens in a new tab)
o1 = new stzString("_/♥\__/♥\__/♥♥_")
o1.ReplaceXT(:Last, "♥", :With = "\")
# the last heart becomes a backslash
? o1.Content()_/♥\__/♥\__/♥\_
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 191_replacext_last.ring(opens in a new tab)
o1 = new stzString("~♥/♥\~♥")
o1.ReplaceXT("♥", :AtPositions = [2, 7], :With = "~")
# hearts at 2 and 7 become ~
? o1.Content()~~/♥\~~
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 193_replacext_atpositions.ring(opens in a new tab)
and 12 more in the tests
The extensions of this method
Each extension, and whether it exists for this method; an extension that exists combines with the others (FindSTCS).
Every example is a test file of the library, run inside the library for this page; only those whose output kept every promise their file wrote are shown.
See also
- The class stzString
- The area's reference: String
- The other methods in these examples: stzString.Count · stzString.Insert · stzString.Redo · stzString.Remove · stzString.ReplaceAll · stzString.ReplaceByMany · stzString.ReplaceFirst · stzString.ReplaceSubStringBoundedBy · stzString.Section · stzString.Undo
- How-to: Replace occurrences of one substring with another

