Sidechair

str.startswith()

Browse the reference

Returns true when a string begins with the text you give.

Try it in the editor

str.startswith(source, str) compares the opening characters of source with str. The comparison is case-sensitive.

Every string starts with an empty string. It is a quick way to group symbols by prefix.

Syntax

Pine Script
str.startswith(source: const string, str: const string) -> const bool
str.startswith(source: simple string, str: simple string) -> simple bool
str.startswith(source: series string, str: series string) -> series bool

Arguments

NameTypeDefaultDescription
sourceconst/simple/series stringrequiredThe text whose beginning is checked. The test is case sensitive.
strconst/simple/series stringrequiredThe prefix to compare with the start of source. An empty prefix always matches.

Returns

const/simple/series bool: true if source begins with str.

Remarks

Example

Pine ScriptPrefix testOpen in editor
//@version=6
indicator("Starts with")
plot(str.startswith(syminfo.ticker, "NV") ? 1 : 0, "Starts with NV", color = color.green, style = plot.style_stepline)

See also

Runs on Sidechair