str.replace

Substitutes one piece of text for another inside a string. The source, the old text and the new text are required; the count is optional.

str.replace(const string source, const string old, const string new, const int count) → const string
str.replace(input string source, input string old, input string new, input int count) → input string
str.replace(series string source, series string old, series string new, series int count) → series string
str.replace(simple string source, simple string old, simple string new, simple int count) → simple string
ParameterTypeRequiredDescription
sourceconst stringyesthe string to work on
oldconst stringyesthe text to replace
newconst stringyesthe text to put in its place
countconst intnooptional; how many occurrences to replace

Returns const string or input string or series string or simple string — A string in the form of the arguments you pass.

indicator("One replacement")
alert(str.replace("a-b-c", "-", ":"))
plot(close)

See also str.contains · str.endswith · str.format_time

Part of the function index.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade