Returns how many characters a string contains.
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
str.length(string: const string) -> const int
str.length(string: simple string) -> simple int
str.length(string: series string) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| string | const/ | required | The 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
//@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