Sidechair

str.contains()

Browse the reference

Returns true when a string includes another string anywhere inside it.

Try it in the editor

str.contains(source, str) checks whether str appears in source. The match is case-sensitive and does not need to touch either end.

An empty search string is found in every source. To search from one end only, use str.startswith or str.endswith, and str.pos tells you where the match begins.

Syntax

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

Arguments

NameTypeDefaultDescription
sourceconst/simple/series stringrequiredThe text to look inside. The test is case sensitive.
strconst/simple/series stringrequiredThe piece of text to look for. An empty string is always found.

Returns

const/simple/series bool: true if source contains str, otherwise false.

Remarks

  • Lower-case both sides first for a case-insensitive check: str.contains(str.lower(a), str.lower(b)).

Example

Pine ScriptHighlight when the symbol name has an exchangeOpen in editor
//@version=6
indicator("Contains")
hasN = str.contains(syminfo.ticker, "N")
bgcolor(hasN ? color.new(color.green, 85) : color.new(color.red, 85))
plot(close, "Close")

See also

Runs on Sidechair