Skip to content

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 string

Also a method: source.char(index).

The character at index, counting from 0, or na outside the string. See AmenoScript's built-ins.

ParameterDescription
source
series string
The string.
index
series int
Which character.

str.concat ​

AmenoScript only
ameno
str.concat(strings, ...) → series string

All of its arguments joined into one string, in order. See AmenoScript's built-ins.

ParameterDescription
strings
series string
The first string.
...
series string
Any number of further strings.

str.contains ​

pine
str.contains(source, str) → series bool

Also a method: source.contains(str).

Whether source holds str anywhere.

ParameterDescription
source
string
The string to search.
str
string
The text to look for.

str.endswith ​

pine
str.endswith(source, str) → series bool

Also a method: source.endswith(str).

Whether source ends with str.

ParameterDescription
source
string
The string to test.
str
string
The ending to look for.

str.format ​

pine
str.format(formatString, arg0, ...) → series string

formatString 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.

ParameterDescription
formatString
series string
The text, with a {N} where argument N goes.
arg0
series 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 string

A 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.

ParameterDefaultDescription
time
series int
The moment, in milliseconds since 1970, such as time.
format
series string
"yyyy-MM-dd'T'HH:mm:ssZ"The pattern.
timezone
series 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 int

Also a method: string.length().

The number of characters. A na string has 0.

Parameter
string
string

str.lower ​

pine
str.lower(source) → series string

Also a method: source.lower().

The string in lower case. A na reads na.

Parameter
source
string

str.match ​

pine
str.match(source, regex) → series string

Also 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 "".

ParameterDescription
source
string
The string to search.
regex
string
The pattern.

str.pos ​

pine
str.pos(source, str) → series int

Also a method: source.pos(str).

Where str first starts in source, counting from 0, or na if it isn't there.

ParameterDescription
source
string
The string to search.
str
string
The text to look for.

str.repeat ​

pine
str.repeat(source, repeat, separator) → series string

Also 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.

ParameterDefaultDescription
source
string
The string to repeat.
repeat
int
How many copies.
separator
string
""What goes between two copies.

str.replace ​

pine
str.replace(source, target, replacement) → series string

Also 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.

ParameterDescription
source
series string
The string to change.
target
series string
The text to replace.
replacement
series string
The text to put in its place.

str.replace_all ​

pine
str.replace_all(source, target, replacement) → series string

Also a method: source.replace_all(target, replacement).

source with every target replaced by replacement.

ParameterDescription
source
string
The string to change.
target
string
The text to replace.
replacement
string
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.

ParameterDescription
string
series string
The string to split.
separator
series string
The text between parts.

str.startswith ​

pine
str.startswith(source, str) → series bool

Also a method: source.startswith(str).

Whether source starts with str.

ParameterDescription
source
string
The string to test.
str
string
The beginning to look for.

str.substring ​

pine
str.substring(source, begin_pos, end_pos) → series string

Also 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.

ParameterDescription
source
string
The string to cut.
begin_pos
int
Where the part starts.
end_pos
int
Where it stops. The end of the string if left out.

str.tonumber ​

pine
str.tonumber(string) → series float

Also 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
string
string

str.tostring ​

pine
str.tostring(value, format) → series string

A 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.

ParameterDescription
value
int/float
The value to write.
format
string
How to write a number.

str.trim ​

pine
str.trim(source) → series string

Also a method: source.trim().

The string without the spaces at either end. A na reads "".

Parameter
source
string

str.trim_left ​

AmenoScript only
ameno
str.trim_left(source) → series string

Also a method: source.trim_left().

The string without the spaces at its start. See AmenoScript's built-ins.

Parameter
source
series string

str.trim_right ​

AmenoScript only
ameno
str.trim_right(source) → series string

Also a method: source.trim_right().

The string without the spaces at its end. See AmenoScript's built-ins.

Parameter
source
series string

str.upper ​

pine
str.upper(source) → series string

Also a method: source.upper().

The string in upper case. A na reads na.

Parameter
source
string

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.