str
Text.
#Functions
#str.containsfunction
true when str occurs in source.
str.contains(source: string, str: string): bool| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
str | string | The text to look for. |
Returns bool.
Example
const b = str.contains(market.id, "BTC")Since ChartScript 1
#str.endswithfunction
true when source ends with str.
str.endswith(source: string, str: string): bool| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
str | string | The text to look for. |
Returns bool.
Example
const b = str.endswith(market.symbol, "USDT")Since ChartScript 1
#str.formatfunction
Fills {0}, {1} ... with the arguments.
str.format(formatString: string): stringstr.format(formatString: string, arg: T, …): string| Parameter | Type | Description |
|---|---|---|
formatString | string | The pattern: {0}, {1}, ... with optional ,number,#.## formats. |
arg | T | A value. |
Returns string.
Example
const s = str.format("{0} at {1,number,#.##}", market.symbol, close)Since ChartScript 1
#str.format_timefunction
A time as text.
str.format_time(time: int, { format?: string = "yyyy-MM-dd'T'HH:mm:ssZ", timezone?: string = "UTC" }): string| Parameter | Type | Description |
|---|---|---|
time | int | A time in milliseconds since 1970 (UTC). |
format | stringdefault "yyyy-MM-dd'T'HH:mm:ssZ" | The number format (format.*). |
timezone | stringdefault "UTC" | An IANA time zone such as "UTC" or "America/New_York". |
Returns string.
Example
const s = str.format_time(time, "yyyy-MM-dd HH:mm")Since ChartScript 1
#str.lengthfunction
The number of characters.
str.length(string: string): int| Parameter | Type | Description |
|---|---|---|
string | string | The text. |
Returns int.
Example
const n = str.length(market.symbol)Since ChartScript 1
#str.lowerfunction
Lower case.
str.lower(source: string): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
Returns string.
Example
const s = str.lower(market.base)Since ChartScript 1
#str.matchfunction
The first match of a pattern, or "".
str.match(source: string, regex: string): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
regex | string | A pattern (a safe, length-capped subset). |
Returns string.
Example
const s = str.match(market.symbol, "USD.?")Since ChartScript 1
#str.posfunction
The position of str in source, or na.
str.pos(source: string, str: string): int| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
str | string | The text to look for. |
Returns int.
Example
const p = str.pos(market.id, ":")Since ChartScript 1
#str.repeatfunction
The text repeated.
str.repeat(source: string, repeat: int, { separator?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
repeat | int | How many times. |
separator | stringdefault "" | The text placed between the parts. |
Returns string.
Example
const s = str.repeat("*", 3)Since ChartScript 1
#str.replacefunction
Replaces one occurrence (0 = the first).
str.replace(source: string, target: string, replacement: string, { occurrence?: int = 0 }): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
target | string | The text to replace. |
replacement | string | The replacement. |
occurrence | intdefault 0 | Which occurrence: 0 = the latest. |
Returns string.
Example
const s = str.replace(market.id, ":", "/")Since ChartScript 1
#str.replace_allfunction
Replaces every occurrence.
str.replace_all(source: string, target: string, replacement: string): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
target | string | The text to replace. |
replacement | string | The replacement. |
Returns string.
Example
const s = str.replace_all(market.id, ":", " ")Since ChartScript 1
#str.splitfunction
Splits the text into an array.
str.split(string: string, separator: string): array<string>| Parameter | Type | Description |
|---|---|---|
string | string | The text. |
separator | string | The text placed between the parts. |
Returns array<string>.
Example
const parts = str.split(market.id, ":")Since ChartScript 1
#str.startswithfunction
true when source starts with str.
str.startswith(source: string, str: string): bool| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
str | string | The text to look for. |
Returns bool.
Example
const b = str.startswith(market.symbol, "BTC")Since ChartScript 1
#str.substringfunction
Part of the text.
str.substring(source: string, begin_pos: int): stringstr.substring(source: string, begin_pos: int, end_pos: int): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
begin_pos | int | The first character (0-based). |
end_pos | int | One past the last character. |
Returns string.
Example
const s = str.substring(market.symbol, 0, 3)Since ChartScript 1
#str.tonumberfunction
The number in the text, or na.
str.tonumber(string: string): float| Parameter | Type | Description |
|---|---|---|
string | string | The text. |
Returns float.
Example
const n = str.tonumber("42.5")Since ChartScript 1
#str.tostringfunction
The value as text; format "#.##", "0.00", format.mintick, format.percent or format.volume.
str.tostring(value: T, { format?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
value | T | The value. |
format | stringdefault "" | The number format (format.*). |
Returns string.
Example
const s = str.tostring(close, "#.##")Since ChartScript 1
#str.tplfunction
A text from a template with {0}, {1} ... (numbers as str.tostring writes them).
str.tpl(template: string, values: T, …): string| Parameter | Type | Description |
|---|---|---|
template | string | The text with {0}, {1} ... places. |
values | T | The values. |
Returns string.
Example
const s = str.tpl("{0} {1}", "POC", close)Since ChartScript 1
#str.trimfunction
Removes spaces at both ends.
str.trim(source: string): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
Returns string.
Example
const s = str.trim(" a ")Since ChartScript 1
#str.upperfunction
Upper case.
str.upper(source: string): string| Parameter | Type | Description |
|---|---|---|
source | string | The series to read. |
Returns string.
Example
const s = str.upper(market.base)Since ChartScript 1