trimString method

String trimString(
  1. String chars
)

Trims the characters given by chars from before and after String.

Stringの前後からcharsで与えられた文字をトリムします。

final text = "__text___";
final trimed = text.trimString("_"); // "text"

Implementation

String trimString(String chars) {
  final pattern = chars.isNotEmpty
      ? RegExp("^[$chars]+|[$chars]+\$")
      : RegExp(r"^\s+|\s+$");
  return replaceAll(pattern, "");
}