Sidechair

str.replace_all()

Browse the reference

Replaces every occurrence of a target text with a replacement.

Try it in the editor

str.replace_all swaps each non-overlapping match of the target for the replacement. Passing an empty replacement deletes the target.

Typical uses are stripping separators before str.tonumber, or swapping a placeholder for a value.

Syntax

Pine Script
str.replace_all(source: simple string, target: simple string, replacement: simple string) -> simple string
str.replace_all(source: series string, target: series string, replacement: series string) -> series string

Arguments

NameTypeDefaultDescription
sourcesimple/series stringrequiredThe text to change. Every occurrence of target in it is replaced.
targetsimple/series stringrequiredThe piece of text to find and swap out everywhere. The match is case sensitive.
replacementsimple/series stringrequiredThe text that replaces each match.

Returns

simple/series string: the edited text.

Remarks

  • An empty target inserts the replacement before every character and at the end.

Example

Pine ScriptClean a number with separatorsOpen in editor
//@version=6
indicator("Replace all")
clean = str.replace_all("1,250,000", ",", "")
plot(str.tonumber(clean), "Parsed", color = color.teal, style = plot.style_stepline)

See also

Runs on Sidechair