splitLast method

List<string> splitLast(
  1. string pattern
)

Splits the string using the specified pattern and returns a list containing the last element and the remaining elements joined by the pattern. If the string cannot be split, it returns a list containing the original string.

Implementation

List<string> splitLast(string pattern) {
  var parts = split(pattern);
  if (parts.length < 2) {
    return [this];
  }
  var last = parts.removeLast();
  return [parts.join(pattern), last];
}