On 7/7/21 3:52 PM, Sebastiaan Koppe wrote:
On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote:
On 7/7/21 5:54 AM, rassoc wrote:
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote:
So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully).


Without considering the more general case, isn't that just splitter-joiner?

No, splitter-joiner would make a range of characters, I want a range of strings.

Just lift each item in a range then:

```d
import std;

auto foo(string s, string sp, string j) @nogc {
      return s.splitter(sp).map!(i => only(i)).joiner(only(j));
}

void main() {
     foo("ab,cd,ef,gh", ",", "##").writeln; // => ["ab", "##", "cd", "##", "ef", "##", "gh"]
}
```

Thanks! This is exactly what I was reaching for. `only` is one of the coolest functions (I use it elsewhere too).

-Steve

Reply via email to