to delete the '\0' characters

Salih Dincer salihdb at hotmail.com
Thu Sep 22 21:31:50 UTC 2022


On Thursday, 22 September 2022 at 20:53:28 UTC, Salih Dincer 
wrote:
>
> ```d
> string splitz(string s)
> {
>   import std.string : indexOf;
>   size_t seekPos = s.indexOf('\0');
>   return s[0..seekPos];
> }
> ```

I ignored the possibility of not finding '\0'. I'm fixing it now:

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

But I also wish it could be like this:

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

SDB at 79




More information about the Digitalmars-d-learn mailing list