to delete the '\0' characters
Paul Backus
snarwin at gmail.com
Thu Sep 22 14:23:20 UTC 2022
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;
}
```
More information about the Digitalmars-d-learn
mailing list