On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer wrote:
Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html

```d
auto foo(string s)
{
  string r;
  foreach(c; s)
  {
    if(c > 0)
    {
      r ~= c;
    }
  }
  return r;
}
```

```d
import std.algorithm : filter;
import std.utf : byCodeUnit;
import std.array : array;

string removeZeroes(string s)
{
    return s.byCodeUnit
        .filter!(c => c != '\0')
        .array;
}
```

Reply via email to