Sidechair

str.length()

Browse the reference

Returns how many characters a string contains.

Try it in the editor

str.length counts every character, spaces included. An empty string has length 0.

Use it to validate user input, to pad text to a fixed width, or as the end position for str.substring.

Syntax

Pine Script
str.length(string: const string) -> const int
str.length(string: simple string) -> simple int
str.length(string: series string) -> series int

Arguments

NameTypeDefaultDescription
stringconst/simple/series stringrequiredThe text to count characters in. An empty string gives 0.

Returns

const/simple/series int: the number of characters.

Remarks

  • Counting is per character, so a string of three letters returns 3 whatever the font.

Example

Pine ScriptDigits before the decimal pointOpen in editor
//@version=6
indicator("Digits")
whole = str.tostring(math.floor(close))
plot(str.length(whole), "Whole digits", color = color.purple, style = plot.style_stepline)

See also

Runs on Sidechair