Skip to content
Algo Trade Analytics Docs

str.replace() - Pine Script Function

Returns a new string with the Nth occurrence of the target string replaced by the replacement string, where N is specified in occurrence.

str.replace(source, target, replacement, occurrence) → const string
NameTypeDescription
sourceconst stringSource string.

Processed string.

//@version=6
indicator("str.replace")
var source = "FTX:BTCUSD / FTX:BTCEUR"// Replace first occurrence of "FTX" with "BINANCE" replacement stringvar newSource = str.replace(source, "FTX", "BINANCE", 0)
if barstate.islastconfirmedhistory // Display "BINANCE:BTCUSD / FTX:BTCEUR"
label.new(bar_index, high, text = newSource)