On Friday, 10 December 2021 at 11:06:21 UTC, IGotD- wrote:
On Friday, 10 December 2021 at 06:24:27 UTC, Rumbu wrote:
Since it seems there is a contest here:
```d
"abc;def;ghi".split(';').join();
```
:)
Would that become two for loops or not?
I thought it's a beauty contest.
```d
string stripsemicolons(string s)
{
string result;
// prevent reallocations
result.length = s.length;
result.length = 0;
//append to string only when needed
size_t i = 0;
while (i < s.length)
{
size_t j = i;
while (i < s.length && s[i] != ';')
++i;
result ~= s[j..i];
}
}
```