what exactly is string length?

Computermatronic computermatronic at gmail.com
Fri Apr 2 05:10:21 UTC 2021


On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote:
> Ahh, I got what I see (from writeln) is not what get string 
> here ;-)
>
> And I just tried:
>
> string t = text("head-", strip(s), "-tail");
>
> It's the same behavior.
>
> So how can I trim the leading & trailing `\0` from the static 
> char array?

strip only removes whitespace, not null characters. You'd have to 
do something like
```d string t = cast(string)text("head-", s, "-tail").filter!`a 
!= '\0'`().array;```
I would assume there would be a better way, but I haven't been 
able to find a dedicated function for stripping null chars in std.


More information about the Digitalmars-d-learn mailing list