removeWrappingChar method
Removes the specified char
from the beginning and/or end of the string.
Implementation
String removeWrappingChar(String char, {bool trimFirst = true}) {
// Method entry point.
// FIX #1: Trim the string first if requested.
String str = trimFirst ? trim() : this;
// Check and remove the prefix if it exists.
if (str.startsWith(char)) {
// FIX #2: Remove the full length of the char, not just 1.
str = str.substring(char.length);
}
// Check and remove the suffix if it exists.
if (str.endsWith(char)) {
// FIX #2: Remove the full length of the char, not just 1.
str = str.substring(0, str.length - char.length);
}
// Return the processed string.
return str;
}