Trims whitespace or specified characters from both ends of a string.
trim(x:string, [chars:string]) -> string
Description
Section titled “Description”The trim
function removes characters from both ends of x
.
When called with one argument, it removes leading and trailing whitespace.
When called with two arguments, it removes any characters found in chars
from
both ends of the string.
x: string
Section titled “x: string”The string to trim.
chars: string (optional)
Section titled “chars: string (optional)”A string where each character represents a character to remove. Any character found in this string will be trimmed from both ends.
Defaults to whitespace characters.
Examples
Section titled “Examples”Trim whitespace from both ends
Section titled “Trim whitespace from both ends”from {x: " hello ".trim()}
{x: "hello"}
Trim specific characters
Section titled “Trim specific characters”from {x: "/path/to/file/".trim("/")}
{x: "path/to/file"}
Trim multiple characters
Section titled “Trim multiple characters”from {x: "--hello--world--".trim("-")}
{x: "hello--world"}