Splits a string at every separator and returns the pieces as an array of strings.
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
str.split(string: series string, separator: series string) -> array<string>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| string | series string | required | The text to cut into pieces at every separator. The pieces come back as an array of strings. |
| separator | series string | required | The text that marks the cut points. |
Returns
array<string>: array<string> of the pieces, in order.
Remarks
- Read pieces with
array.get, and convert numbers withstr.tonumber.
Example
//@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