On 02/04/2021 6:10 PM, Computermatronic wrote:
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.

If you know it has null terminators you can use fromStringz.
But this is a case of you should store the length.
          • Re: w... mw via Digitalmars-d-learn
            • ... rikki cattermole via Digitalmars-d-learn
              • ... mw via Digitalmars-d-learn
              • ... H. S. Teoh via Digitalmars-d-learn
              • ... H. S. Teoh via Digitalmars-d-learn
              • ... mw via Digitalmars-d-learn
              • ... Paul Backus via Digitalmars-d-learn
          • Re: w... Computermatronic via Digitalmars-d-learn
            • ... mw via Digitalmars-d-learn
              • ... Computermatronic via Digitalmars-d-learn
              • ... rikki cattermole via Digitalmars-d-learn
              • ... mw via Digitalmars-d-learn
              • ... Berni44 via Digitalmars-d-learn
      • Re: what exac... mw via Digitalmars-d-learn
  • Re: what exactly is st... H. S. Teoh via Digitalmars-d-learn
  • Re: what exactly is st... Виталий Фадеев via Digitalmars-d-learn

Reply via email to