str.pos
Reports the position at which one string sits inside another. The result is an int. This edition does not state what that int is counted from, nor what it reads when there is no match, so do not rely on either.
str.pos(const string source, const string str) → const intstr.pos(input string source, input string str) → input intstr.pos(series string source, series string str) → series intstr.pos(simple string source, simple string str) → simple int| Parameter | Type | Required | Description |
|---|---|---|---|
source | const string | yes | the string to search in |
str | const string | yes | the string whose position you want |
Returns const int or input int or series int or simple int — A series int: the position of needle, counted from zero, or -1 where it does not occur. The position is a byte offset, so it is not interchangeable with the character positions str.substring takes once the text goes outside ASCII.
indicator("Position of USD in a string")
plot(str.pos("EURUSD", "USD"))See also str.contains · str.endswith · str.format_time
Part of the function index.
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.