Trims leading and trailing characters (whitespace by default) from a string. Also available as string.trim (though not provided by the Lua standard library).


See also Utility functions.

Signature:

text = strtrim("str" [, "trimChars"])

Arguments:

  • str - A string to trim (string)
  • trimChars - A string listing the characters to be trimmed (e.g. "[]{}()" to trim leading and trailing brackets, braces, and parentheses); if nil or omitted, whitespace characters (space, tab, newline, etc) are trimmed (string)

Returns:

  • text - The trimmed string (string)

Examples:

strtrim("   This is a test   ")
-- Returns "This is a test"
    
strtrim("121abc456", "615")
-- Returns "21abc4"