trimString method
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, "");
}