Sidechair

str.split()

Browse the reference

Splits a string at every separator and returns the pieces as an array of strings.

Try it in the editor

str.split(string, separator) cuts the text wherever the separator occurs and drops the separator itself. "a,b,c" split on "," gives three items.

Two separators in a row produce an empty string between them. A text with no separator comes back as an array of one item.

Syntax

Pine Script
str.split(string: series string, separator: series string) -> array<string>

Arguments

NameTypeDefaultDescription
stringseries stringrequiredThe text to cut into pieces at every separator. The pieces come back as an array of strings.
separatorseries stringrequiredThe text that marks the cut points.

Returns

array<string>: array<string> of the pieces, in order.

Remarks

Example

Pine ScriptRead a list settingOpen in editor
//@version=6
indicator("Split")
parts = str.split("10,20,30", ",")
total = 0.0
for i = 0 to array.size(parts) - 1
    total += nz(str.tonumber(array.get(parts, i)))
plot(total, "Sum of list", color = color.purple, style = plot.style_stepline)

See also

Runs on Sidechair