replaceLastNCharacters method

  1. @useResult
String replaceLastNCharacters(
  1. int n,
  2. String replacementChar
)

Returns a new string with the last n characters replaced by replacementChar.

Implementation

@useResult
String replaceLastNCharacters(int n, String replacementChar) {
  if (n <= 0 || n > length) {
    return this;
  }

  return substringSafe(0, length - n) + replacementChar * n;
}