Replaces every occurrence of a target text with a replacement.
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
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 stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | simple/ | required | The text to change. Every occurrence of target in it is replaced. |
| target | simple/ | required | The piece of text to find and swap out everywhere. The match is case sensitive. |
| replacement | simple/ | required | The 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
//@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