Skip to content
ChartDeck ChartScript docs Account Open the terminal

str

Text.

#Functions

#str.containsfunction

true when str occurs in source.

str.contains(source: string, str: string): bool
ParameterTypeDescription
sourcestringThe series to read.
strstringThe text to look for.

Returns bool.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
sourcestringThe series to read.
strstringThe text to look for.

Returns bool.

Example

ChartScriptFragmentOpen in editor
const b = str.endswith(market.symbol, "USDT")

Since ChartScript 1

#str.formatfunction

Fills {0}, {1} ... with the arguments.

str.format(formatString: string): string
str.format(formatString: string, arg: T, …): string
ParameterTypeDescription
formatStringstringThe pattern: {0}, {1}, ... with optional ,number,#.## formats.
argTA value.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
formatstringdefault "yyyy-MM-dd'T'HH:mm:ssZ"The number format (format.*).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
stringstringThe text.

Returns int.

Example

ChartScriptFragmentOpen in editor
const n = str.length(market.symbol)

Since ChartScript 1

#str.lowerfunction

Lower case.

str.lower(source: string): string
ParameterTypeDescription
sourcestringThe series to read.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
sourcestringThe series to read.
regexstringA pattern (a safe, length-capped subset).

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
sourcestringThe series to read.
strstringThe text to look for.

Returns int.

Example

ChartScriptFragmentOpen in editor
const p = str.pos(market.id, ":")

Since ChartScript 1

#str.repeatfunction

The text repeated.

str.repeat(source: string, repeat: int, { separator?: string = "" }): string
ParameterTypeDescription
sourcestringThe series to read.
repeatintHow many times.
separatorstringdefault ""The text placed between the parts.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
sourcestringThe series to read.
targetstringThe text to replace.
replacementstringThe replacement.
occurrenceintdefault 0Which occurrence: 0 = the latest.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
sourcestringThe series to read.
targetstringThe text to replace.
replacementstringThe replacement.

Returns string.

Example

ChartScriptFragmentOpen in editor
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>
ParameterTypeDescription
stringstringThe text.
separatorstringThe text placed between the parts.

Returns array<string>.

Example

ChartScriptFragmentOpen in editor
const parts = str.split(market.id, ":")

Since ChartScript 1

#str.startswithfunction

true when source starts with str.

str.startswith(source: string, str: string): bool
ParameterTypeDescription
sourcestringThe series to read.
strstringThe text to look for.

Returns bool.

Example

ChartScriptFragmentOpen in editor
const b = str.startswith(market.symbol, "BTC")

Since ChartScript 1

#str.substringfunction

Part of the text.

str.substring(source: string, begin_pos: int): string
str.substring(source: string, begin_pos: int, end_pos: int): string
ParameterTypeDescription
sourcestringThe series to read.
begin_posintThe first character (0-based).
end_posintOne past the last character.

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
stringstringThe text.

Returns float.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
valueTThe value.
formatstringdefault ""The number format (format.*).

Returns string.

Example

ChartScriptFragmentOpen in editor
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
ParameterTypeDescription
templatestringThe text with {0}, {1} ... places.
valuesTThe values.

Returns string.

Example

ChartScriptFragmentOpen in editor
const s = str.tpl("{0}  {1}", "POC", close)

Since ChartScript 1

#str.trimfunction

Removes spaces at both ends.

str.trim(source: string): string
ParameterTypeDescription
sourcestringThe series to read.

Returns string.

Example

ChartScriptFragmentOpen in editor
const s = str.trim("  a  ")

Since ChartScript 1

#str.upperfunction

Upper case.

str.upper(source: string): string
ParameterTypeDescription
sourcestringThe series to read.

Returns string.

Example

ChartScriptFragmentOpen in editor
const s = str.upper(market.base)

Since ChartScript 1

The ChartScript documentation is in English for now; translations will follow.