betweenLast method

String betweenLast(
  1. String start,
  2. String end
)

Get the substring of a string between the last occurrence of two strings.

Implementation

String betweenLast(String start, String end) {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  if (this!.isEmpty) {
    return '';
  }
  final startIndex = this!.lastIndexOf(start);
  if (startIndex == -1) {
    return '';
  }
  final endIndex = this!.lastIndexOf(end, startIndex + start.length);
  if (endIndex == -1) {
    return '';
  }
  return this!.substring(startIndex + start.length, endIndex);
}