trim function

String trim(
  1. String str, [
  2. String? chars
])

Removes the given chars from both ends of the string.

If chars is null, leading and trailing whitespace is removed.

Example:

trim('  hello  '); // 'hello'
trim('xxhelloxx', 'x'); // 'hello'

Implementation

String trim(String str, [String? chars]) {
  return rtrim(ltrim(str, chars), chars);
}