trim function

String trim (String str, [ String chars ])

trim characters (whitespace by default) from both sides of the input

Implementation

String trim(String str, [String chars]) {
  RegExp pattern =
      (chars != null) ? RegExp('^[$chars]+|[$chars]+\$') : RegExp(r'^\s+|\s+$');
  return str.replaceAll(pattern, '');
}