Skip to content

String Trim

The string::trim function removes all leading and trailing whitespace characters from a string.

Syntax

string::trim(<string>, <chars>)

Parameters

  • string: The input string to be trimmed.
  • string: A string with one or more characters to remove from either side of the string.

Returns

  • String: A new string without leading or trailing whitespace.

Example

Try it out below!
string::trim("  ??hello world!!  ", "?! ")

This function is useful for cleaning up strings by removing unwanted spaces at the start and end.