Returns the index where a string first appears inside another, or na if it does not.
str.pos(source, str) gives the position of the first match, counting from 0. A match at the very start returns 0.
A missing match returns na, not -1, so test with na() or nz() before using the result as an index.
Syntax
str.pos(source: const string, str: const string) -> const int
str.pos(source: simple string, str: simple string) -> simple int
str.pos(source: series string, str: series string) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | const/ | required | The text to look inside. The search starts at the first character. |
| str | const/ | required | The piece of text to find. The index of its first match is returned, or na. |
Returns
const/simple/series int: the zero-based index of the first match, or na.
Remarks
- Pair it with
str.substringto cut text around a marker.
Example
//@version=6
indicator("Position")
txt = "alpha:beta"
at = str.pos(txt, ":")
plot(at, "Colon at", color = color.red, style = plot.style_stepline)
plot(str.length(str.substring(txt, at + 1)), "Text after", color = color.green, style = plot.style_stepline)See also
Runs on Sidechair