what exactly is string length?
mw
mingwu at gmail.com
Fri Apr 2 05:39:26 UTC 2021
On Friday, 2 April 2021 at 05:18:49 UTC, H. S. Teoh wrote:
> On Fri, Apr 02, 2021 at 05:05:21AM +0000, mw via
> Digitalmars-d-learn wrote: [...]
>> This is just an example, what if the exact length is not known
>> statically, is there a functions to trim the `\0`s?
>
> What about `s.until('\0')`?
>
> Example:
>
> auto s = "abc\0\0\0def";
> auto t = "blah" ~ s.until('\0').array ~ "boo";
Finally, I'm using:
https://run.dlang.io/is/651lT6
string t = text("head-", s[].until('\0').array, "-tail");
It works for both s = "abc" (with \0), and "abcdef" (full 6
chars, indexOf will return -1 for bad range index).
Thank everyone who helped.
More information about the Digitalmars-d-learn
mailing list