TextReplaceBetween method

String TextReplaceBetween(
  1. String text,
  2. String begin,
  3. String end,
  4. String replacement,
)

Replace text between two specific strings

Implementation

String TextReplaceBetween(
  String text,
  String begin,
  String end,
  String replacement,
) => run(
  () => _debugLabels.TextReplaceBetween(text, begin, end, replacement),
  () {
    final startIdx = text.indexOf(begin);
    if (startIdx == -1) return text;
    final contentStart = startIdx + begin.length;
    final endIdx = text.indexOf(end, contentStart);
    if (endIdx == -1) return text;
    return text.substring(0, contentStart) + replacement + text.substring(endIdx);
  },
);