Appearance
str
How do you turn a value into text for a label or a table? Use str.tostring for one value and str.format to build a sentence from several. The other str.* functions search, cut and compare strings, and each can also be called as a method on the string, as in s.upper().
pine
//@version=6
indicator("Close as text", overlay = true)
if barstate.islast
txt = str.format("{0} closed at {1,number,#.00}", syminfo.ticker, close) // {1} as a number with two decimals
label.new(bar_index, high, txt)A na string is the empty string here, as on TradingView: na("") is true, and str.length of one is 0. A number's na prints as NaN. The formats each function writes, infinities included, are set out in strings.
str.char
AmenoScript only
ameno
str.char(source, index) → series stringAlso a method: source.char(index).
The character at index, counting from 0, or na outside the string. See AmenoScript's built-ins.
| Parameter | Description |
|---|---|
sourceseries string | The string. |
indexseries int | Which character. |
str.concat
AmenoScript only
ameno
str.concat(strings, ...) → series stringAll of its arguments joined into one string, in order. See AmenoScript's built-ins.
| Parameter | Description |
|---|---|
stringsseries string | The first string. |
...series string | Any number of further strings. |
str.contains
pine
str.contains(source, str) → series boolAlso a method: source.contains(str).
Whether source holds str anywhere.
| Parameter | Description |
|---|---|
sourcestring | The string to search. |
strstring | The text to look for. |
str.endswith
pine
str.endswith(source, str) → series boolAlso a method: source.endswith(str).
Whether source ends with str.
| Parameter | Description |
|---|---|
sourcestring | The string to test. |
strstring | The ending to look for. |
str.format
pine
str.format(formatString, arg0, ...) → series stringformatString with each {N} replaced by argument N, counting from 0.
A placeholder can say how to write its value: {0,number,#.##} with a pattern of #, 0, , and ., {0,number,integer}, {0,number,percent} (times 100, whole), {0,number,currency}, and {0,date,yyyy-MM-dd} or {0,time,HH:mm} for a time in milliseconds, written in UTC. A bare {0} writes a number as #,###.###. An infinity writes ∞. See str.format.
| Parameter | Description |
|---|---|
formatStringseries string | The text, with a {N} where argument N goes. |
arg0series any | The value for {0}. |
...series any | The values for {1} and on. |
pine
//@version=6
indicator("A formatted line")
if barstate.islast
s = str.format("{0,number,percent} of the range, on {1,date,yyyy-MM-dd}", (close - low) / (high - low), time)
label.new(bar_index, close, s) // e.g. "73% of the range, on 2025-08-22"
plot(close)str.format_time
pine
str.format_time(time, format, timezone) → series stringA time in milliseconds written by a pattern, in the chart's timezone unless you name one.
The pattern takes y, M (MMM and MMMM for the month's name), d, H, h, a, m, s, Z, z and text in single quotes. Day names (EEE) aren't supported and come back as the letters. Each S writes the milliseconds as three digits, so SSS writes nine. See formatting times.
| Parameter | Default | Description |
|---|---|---|
timeseries int | The moment, in milliseconds since 1970, such as time. | |
formatseries string | "yyyy-MM-dd'T'HH:mm:ssZ" | The pattern. |
timezoneseries string | An IANA name such as "America/New_York" or an offset such as "UTC+2". The chart's timezone if left out. |
str.length
pine
str.length(string) → series intAlso a method: string.length().
The number of characters. A na string has 0.
| Parameter |
|---|
stringstring |
str.lower
pine
str.lower(source) → series stringAlso a method: source.lower().
The string in lower case. A na reads na.
| Parameter |
|---|
sourcestring |
str.match
pine
str.match(source, regex) → series stringAlso a method: source.match(regex).
The first part of source that the regular expression matches, or "" when nothing does.
The pattern is read as a JavaScript regular expression, which agrees with TradingView's Java ones on everyday patterns. A pattern that doesn't compile reads "".
| Parameter | Description |
|---|---|
sourcestring | The string to search. |
regexstring | The pattern. |
str.pos
pine
str.pos(source, str) → series intAlso a method: source.pos(str).
Where str first starts in source, counting from 0, or na if it isn't there.
| Parameter | Description |
|---|---|
sourcestring | The string to search. |
strstring | The text to look for. |
str.repeat
pine
str.repeat(source, repeat, separator) → series stringAlso a method: source.repeat(repeat, separator).
source written repeat times, with separator between the copies.
A count of 0 gives "", and a negative one na.
| Parameter | Default | Description |
|---|---|---|
sourcestring | The string to repeat. | |
repeatint | How many copies. | |
separatorstring | "" | What goes between two copies. |
str.replace
pine
str.replace(source, target, replacement) → series stringAlso a method: source.replace(target, replacement).
source with the first target replaced by replacement.
The occurrence argument is ignored
TradingView takes a fourth argument, occurrence, which picks the match to replace. This engine always replaces the first, so str.replace("a-b-c", "-", "+", 1) reads a+b-c here and a-b+c on TradingView.
| Parameter | Description |
|---|---|
sourceseries string | The string to change. |
targetseries string | The text to replace. |
replacementseries string | The text to put in its place. |
str.replace_all
pine
str.replace_all(source, target, replacement) → series stringAlso a method: source.replace_all(target, replacement).
source with every target replaced by replacement.
| Parameter | Description |
|---|---|
sourcestring | The string to change. |
targetstring | The text to replace. |
replacementstring | The text to put in its place. |
str.split
pine
str.split(string, separator) → array<string>Also a method: string.split(separator).
The parts of string between each separator, as a string array.
An empty separator splits it into single characters. A split that would make more than 100,000 parts stops the script.
| Parameter | Description |
|---|---|
stringseries string | The string to split. |
separatorseries string | The text between parts. |
str.startswith
pine
str.startswith(source, str) → series boolAlso a method: source.startswith(str).
Whether source starts with str.
| Parameter | Description |
|---|---|
sourcestring | The string to test. |
strstring | The beginning to look for. |
str.substring
pine
str.substring(source, begin_pos, end_pos) → series stringAlso a method: source.substring(begin_pos, end_pos).
The part of source from begin_pos up to, but not including, end_pos, counting from 0.
With no end_pos it runs to the end.
| Parameter | Description |
|---|---|
sourcestring | The string to cut. |
begin_posint | Where the part starts. |
end_posint | Where it stops. The end of the string if left out. |
str.tonumber
pine
str.tonumber(string) → series floatAlso a method: string.tonumber().
The number a string spells, or na when it isn't one.
Spaces around the number are allowed, and so is an exponent, as in "1e3". Anything else in the string, as in "42abc", reads na.
| Parameter |
|---|
stringstring |
str.tostring
pine
str.tostring(value, format) → series stringA value written as text, by format if you give one.
A float is rounded to 9 decimal places, so 0.1 + 0.2 writes 0.3. A bool writes true or false, a colour its hex code, and an array its elements in brackets. format takes format.mintick, format.price, format.percent (the value with two decimals and %, not times 100), format.volume (1.5K, 2.3M and on to T) or a pattern such as "#.##". See str.tostring.
| Parameter | Description |
|---|---|
valueint/float | The value to write. |
formatstring | How to write a number. |
str.trim
pine
str.trim(source) → series stringAlso a method: source.trim().
The string without the spaces at either end. A na reads "".
| Parameter |
|---|
sourcestring |
str.trim_left
AmenoScript only
ameno
str.trim_left(source) → series stringAlso a method: source.trim_left().
The string without the spaces at its start. See AmenoScript's built-ins.
| Parameter |
|---|
sourceseries string |
str.trim_right
AmenoScript only
ameno
str.trim_right(source) → series stringAlso a method: source.trim_right().
The string without the spaces at its end. See AmenoScript's built-ins.
| Parameter |
|---|
sourceseries string |
str.upper
pine
str.upper(source) → series stringAlso a method: source.upper().
The string in upper case. A na reads na.
| Parameter |
|---|
sourcestring |