Sidechair

str.endswith()

Browse the reference

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

Try it in the editor

str.endswith(source, str) compares the closing characters of source with str. Upper and lower case letters are treated as different.

It suits suffix checks such as a currency code at the end of a symbol name.

Syntax

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

Arguments

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

Returns

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

Remarks

  • An empty suffix always matches.

Example

Pine ScriptSuffix testOpen in editor
//@version=6
indicator("Ends with")
plot(str.endswith(syminfo.ticker, "A") ? 1 : 0, "Ends with A", color = color.orange, style = plot.style_stepline)

See also

Runs on Sidechair