On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov wrote:
Oooh, finally someone suggested to preallocate storage for all these reinventions of the wheel :D

```
import std.stdio;

char[] dontdothis(string s, int i=0, int skip=0){
    if (s.length == i) return new char[](i - skip);
    if (s[i] == ';') return dontdothis(s, i+1, skip+1);
    auto r = dontdothis(s, i+1, skip);
    r[i-skip] = s[i];
    return r;
}

int main() {
    string s = "abc;def;ab";
    string s_new = cast(string)dontdothis(s);
    writeln(s_new);
    return 0;
}
```

Reply via email to