How can I replace 3rd+ occurrence of a string? I want to keep first and second new lines but replaces all others with empty string in Dart but the question itself is language agnostic

I want to convert

```
a
b
c
d
e
f

```

to

```
a
b
cdef

```