Sidechair

str.format()

Browse the reference

Builds a string from a template, replacing {0}, {1} and so on with the arguments that follow.

Try it in the editor

str.format scans the template for placeholders in curly braces. {0} stands for the first argument after the template, {1} for the second, and each placeholder can appear any number of times.

Add a type and pattern to shape the value: {0,number,#.##} rounds a number to two decimals, {1,number,percent} prints a fraction as a percentage, and {2,date,yyyy-MM-dd} prints a timestamp as a date.

Syntax

Pine Script
str.format(formatString: simple string, arg0, arg1, ...: simple int/float/bool/string) -> simple string
str.format(formatString: series string, arg0, arg1, ...: series int/float/bool/string/array<int/float/bool/string>) -> series string

Arguments

NameTypeDefaultDescription
formatStringsimple string, arg0, arg1, ...: simple int/float/bool/string or series string, arg0, arg1, ...: series int/float/bool/string/array<int/float/bool/string>requiredThe template, with placeholders like {0} or {1,number,#.##}.

Returns

simple/series string: the template with each placeholder replaced.

Remarks

  • Text between single quotes stays literal, which lets you print a brace: '{'.
  • A placeholder with no matching argument is left in the output as written.
  • On Sidechair: placeholders follow MessageFormat rules. A bare {0} holding a number prints with thousands separators and up to three decimals, and {n,date} values print in UTC.

Example

Pine ScriptA readable summaryOpen in editor
//@version=6
indicator("Format")
msg = str.format("Close {0,number,#.##}, range {1,number,0.00}", close, high - low)
plot(str.length(msg), "Message length", color = color.teal, style = plot.style_stepline)
plot(str.length(str.format("{0} and {0}", close)), "Reused placeholder", color = color.gray)

See also

Runs on Sidechair