Softanza
StartFrançais
Softanza
Reference · stzString

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)

Softanza
# Q(@char).IsNotLetter() targets the symbols, leaving spaced words
? Q("ABC♥DEF★GHI♥JKL").ReplaceWQ('Q(@char).IsNotLetter()', :With = " ").Content()
Output
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)

Softanza
o1 = new stzString("R I N G")
o1.Replace(" ", "-")
# Replace() mutates the object
? o1.Content()
Output
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)

Softanza
o1 = new stzString("a + b - c / d = 0")
o1.ReplaceMany([ "+", "-", "/" ], "*")
# all become *
? o1.Content()
Output
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)

Softanza
o1 = new stzString(" isNumber( 0+  @item  ) ")
o1.ReplaceMany([ "" ], 'any')
# the content is unchanged
? o1.Content()
Output
 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)

Softanza
o1 = new stzString("~♥/♥\~~")
o1.ReplaceXT("♥", :At = 2, :With = "~")
# the heart at position 2 becomes '~'
? o1.Content()
Output
~~/♥\~~

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 192_replacext_at.ring(opens in a new tab)

Softanza
o1 = new stzString("one two three four")
o1.ReplaceMany([ "two", "four" ], :By = "---")
# both became dashes
? o1.Content()
Output
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)

Softanza
o1 = new stzString("_♥♥\__/♥\__/♥\_")
o1.ReplaceXT(:First, "♥", :With = "/")
# the first heart becomes a slash
? o1.Content()
Output
_/♥\__/♥\__/♥\_

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 190_replacext_first.ring(opens in a new tab)

Softanza
o1 = new stzString("a + b - c / d = 0")
o1.ReplaceMany([ "+", "-", "/" ], :By = "*")
# +, - and / all become *
? o1.Content()
Output
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)

Softanza
o1 = new stzString("_/♥\__/♥\__/♥♥_")
o1.ReplaceXT(:Last, "♥", :With = "\")
# the last heart becomes a backslash
? o1.Content()
Output
_/♥\__/♥\__/♥\_

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 191_replacext_last.ring(opens in a new tab)

Softanza
o1 = new stzString("~♥/♥\~♥")
o1.ReplaceXT("♥", :AtPositions = [2, 7], :With = "~")
# hearts at 2 and 7 become ~
? o1.Content()
Output
~~/♥\~~

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).

Extension
Exists
What it adds · The names
Q
yes
does what the method does, then returns the object, so the call can be chained · ReplaceQ, ReplaceWQ, ReplaceCSQ, ReplaceXTQ and 1 more
QQ
no
chains on the next, more specific type of object (the Q ladder)
QQQ
no
chains on the most specific type of object (the Q ladder)
QRT
no
returns the result as an object of the requested type
CS
yes
takes a case-sensitivity flag · ReplaceCS, ReplaceCSQ, ReplaceManyCS, ReplaceManyCSQ
ST
no
takes the position to start from (StartingAt)
IB
no
takes bounds that are included (IncludingBounds)
XT
yes
the extended form: more parameters than the base method · ReplaceXT, ReplaceXTQ
XTT
no
yet another extension: a further extended form, after XT
Z
no
includes the position in what it returns
ZZ
no
returns positions as sections, [start, end]
W
yes
selects by a condition · ReplaceW, ReplaceWQ
WF
no
selects by a condition, with the expressive keywords (@NextItem, @PreviousItem...)
D
no
takes a direction, forward or backward (Directional)
F
no
takes a function (the condition or the update is given as a function); the forms document also uses F for the future form, which defers the action
Many
yes
works on a collection of items instead of one (the plural form) · ReplaceMany, ReplaceManyCS, ReplaceManyCSQ
Except
no
takes exceptions, what to leave out (the exceptional form)
U
no
returns the result without duplication

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