removeSurrounding method
Removes from a String both the given prefix
and suffix
if and only
if it starts with the prefix
and ends with the suffix
.
Otherwise returns this String unchanged.
Implementation
String removeSurrounding({required String prefix, required String suffix}) {
assert(prefix != null);
assert(suffix != null);
if (startsWith(prefix) && endsWith(suffix)) {
return substring(prefix.length, length - suffix.length);
} else {
return this;
}
}