removePostfixIfPresent method

String removePostfixIfPresent(
  1. String toRemove
)

Remove the postfix of a String if present or return current String.

Implementation

String removePostfixIfPresent(String toRemove) {
  if (!endsWith(toRemove)) {
    return this;
  }

  final lastIndex = lastIndexOf(toRemove);

  return substring(0, lastIndex);
}