Returns true when a string includes another string anywhere inside it.
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
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 boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | const/ | required | The text to look inside. The test is case sensitive. |
| str | const/ | required | The 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
//@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