replaceLastNCharacters method
Returns a new string with the last n characters replaced by
replacementChar.
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
String replaceLastNCharacters(int n, String replacementChar) {
if (n <= 0 || n > length) {
return this;
}
return substringSafe(0, length - n) + replacementChar * n;
}