removeSurrounding method
Returns the string only if the delimiter exists at both ends, otherwise returns the current string.
Implementation
String? removeSurrounding(String delimiter) {
if (this == null) return null;
final prefix = delimiter;
final suffix = delimiter;
if ((this!.length >= prefix.length + suffix.length) &&
this!.startsWith(prefix) &&
this!.endsWith(suffix)) {
return this!.substring(prefix.length, this!.length - suffix.length);
}
return this;
}