removeSuffix method

String removeSuffix(
  1. String suffix
)

If this String ends with the given suffix, returns a copy of this String with the suffix removed. Otherwise, returns this String.

Implementation

String removeSuffix(String suffix) {
  if (endsWith(suffix)) {
    return substring(0, length - suffix.length);
  } else {
    return this;
  }
}