to delete the '\0' characters

Ali Çehreli acehreli at yahoo.com
Thu Sep 22 21:49:36 UTC 2022


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




More information about the Digitalmars-d-learn mailing list