How to remove the last character(s) from String in Dart [duplicate]

Remove last character:

if (str != null && str.length > 0) {
  str = str.substring(0, str.length - 1);
}

Remove last 5 characters:

if (str != null && str.length >= 5) {
  str = str.substring(0, str.length - 5);
}

Leave a Comment