On 9/22/22 14:31, Salih Dincer wrote:

> string splitz(string s)
> {
>    import std.string : indexOf;
>    auto seekPos = s.indexOf('\0');
>    return seekPos > 0 ? s[0..seekPos] : s;
> }

If you have multiple '\0' chars that you will continue looking for, how about the following?

import std;

auto splitz(string s) {
    return s.splitter('\0');
}

unittest {
    auto data = [ "hello", "and", "goodbye", "world" ];
    auto hasZeros = data.joiner("\0").text;
    assert(hasZeros.count('\0') == 3);
    assert(hasZeros.splitz.equal(data));
}

void main() {
}

Ali


Reply via email to