Returns a string with spaces, tabs and line breaks removed from both ends.
str.trim strips leading and trailing white space. Spaces inside the text stay.
Apply it to user-entered text before comparing or converting it, because a stray space makes str.tonumber give na.
Syntax
str.trim(source: const string) -> const string
str.trim(source: input string) -> input string
str.trim(source: simple string) -> simple string
str.trim(source: series string) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | const/ | required | The text to clean up. Spaces and line breaks at both ends are removed. |
Returns
const/input/simple/series string: the text without white space at either end.
Remarks
- A string of only spaces becomes an empty string.
Example
//@version=6
indicator("Trim")
txt = input.string(" 42 ", "Number")
plot(str.tonumber(str.trim(txt)), "Parsed", color = color.blue, style = plot.style_stepline)See also
Runs on Sidechair