Returns the part of a string from begin_pos up to, but not including, end_pos.
str.substring cuts out a slice of the text. Positions count from 0, so str.substring("chart", 1, 3) returns "ha".
Leave out end_pos to take everything from begin_pos to the end. The begin position has to sit inside the string and the end position cannot be before it or past the end, or the script stops with an error.
Syntax
str.substring(source: const string, begin_pos: const int, end_pos: const int) -> const string
str.substring(source: simple string, begin_pos: simple int, end_pos: simple int) -> simple string
str.substring(source: series string, begin_pos: series int, end_pos: series int) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | const/ | required | The text to cut a piece from. begin_pos and end_pos count its characters from 0. |
| begin_pos | const/ | required | Index of the first character to include. Counts from 0. |
| end_pos | const/ | length of the string | Index just after the last character to include. |
Returns
const/simple/series string: the slice of text.
Remarks
- Check bounds with
str.lengthbefore slicing text that can vary in size.
Example
//@version=6
indicator("Substring")
head = str.substring(syminfo.ticker, 0, 2)
plot(str.length(head), "Length of head", color = color.blue, style = plot.style_stepline)
plot(str.pos(syminfo.ticker, head), "Position of head", color = color.red)See also
Runs on Sidechair