Re: what exactly is string length?

2021-04-02 Thread Berni44 via Digitalmars-d-learn
On Friday, 2 April 2021 at 15:01:07 UTC, mw wrote: BTW, shall I log a writeln() improvement bug ? It's really confusing, e.g as debug print or logs. In my opinion this isn't a bug. The nulls are actually printed: ``` $> rdmd test.d | hd 61 62 63 00 00 00 36 0a 68 65 61 64 2d 61 62

Re: what exactly is string length?

2021-04-02 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote: On Friday, 2 April 2021 at 04:54:07 UTC, Computermatronic wrote: On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote: So you mean inside the writeln() call, the 0s are skipped? Well, if I use `string t` as filename, it will try to looking for a

Re: what exactly is string length?

2021-04-02 Thread Paul Backus via Digitalmars-d-learn
On Friday, 2 April 2021 at 05:39:26 UTC, mw wrote: Finally, I'm using: https://run.dlang.io/is/651lT6 string t = text("head-", s[].until('\0').array, "-tail"); FYI, you don't need the call to `.array` there--`text` accepts input ranges.

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 05:18:49 UTC, H. S. Teoh wrote: On Fri, Apr 02, 2021 at 05:05:21AM +, 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:

Re: what exactly is string length?

2021-04-01 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:32:53 UTC, mw wrote: https://run.dlang.io/is/B4jcno --- import std; import std.conv : text; void main() { char[6] s; s = "abc"; writeln(s, s.length); // abc6, ok it's the static array's length string t = text("head-", s, "-tail"); writeln(t

Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn
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 & trai

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 05:05:21AM +, 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? Another way, if you want to avoid the extra allocation, slice the static array with .indexOf:

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 05:05:21AM +, 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" ~

Re: what exactly is string length?

2021-04-01 Thread Computermatronic via Digitalmars-d-learn
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 on

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 05:01:27 UTC, rikki cattermole wrote: On 02/04/2021 5:51 PM, mw wrote: Then how can I construct `t`? to make this assertion true:    assert(t == "head-abc-tail");  // failed! Slice it. string t = text("head-", s[0 .. 3], "-tail"); http://ddili.org/ders/d.en/slic

Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn
On 02/04/2021 5:51 PM, mw wrote: Then how can I construct `t`? to make this assertion true:    assert(t == "head-abc-tail");  // failed! Slice it. string t = text("head-", s[0 .. 3], "-tail"); http://ddili.org/ders/d.en/slices.html

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:54:07 UTC, Computermatronic wrote: On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote: So you mean inside the writeln() call, the 0s are skipped? Well, if I use `string t` as filename, it will try to looking for a file called: "head-abc\0\0\0-tail" instead of jus

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 04:32:53AM +, mw via Digitalmars-d-learn wrote: [...] > --- > import std; > import std.conv : text; > > > void main() > { > char[6] s; > s = "abc"; > writeln(s, s.length); // abc6, ok it's the static array's length > > string t = text("head-", s, "-ta

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote: On Friday, 2 April 2021 at 04:43:48 UTC, rikki cattermole wrote: On 02/04/2021 5:38 PM, mw wrote: On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote: On 02/04/2021 5:32 PM, mw wrote: --- import std; import std.conv : text; void

Re: what exactly is string length?

2021-04-01 Thread Computermatronic via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote: So you mean inside the writeln() call, the 0s are skipped? Well, if I use `string t` as filename, it will try to looking for a file called: "head-abc\0\0\0-tail" instead of just "head-abc-tail" ? or it's platform dependent? I would imagine

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:43:48 UTC, rikki cattermole wrote: On 02/04/2021 5:38 PM, mw wrote: On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote: On 02/04/2021 5:32 PM, mw wrote: --- import std; import std.conv : text; void main() {     char[6] s;     s = "abc";     writeln(

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:38:37 UTC, mw wrote: On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote: I don't get it, what do you mean by the assertion: assert(t[9] == '\0'); t == "head-abc-tail" Just tried this: https://run.dlang.io/is/SFU5p4 ``` import std; import std.conv

Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn
On 02/04/2021 5:38 PM, mw wrote: On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote: On 02/04/2021 5:32 PM, mw wrote: --- import std; import std.conv : text; void main() {     char[6] s;     s = "abc";     writeln(s, s.length);  // abc6, ok it's the static array's length     str

Re: what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote: On 02/04/2021 5:32 PM, mw wrote: --- import std; import std.conv : text; void main() {    char[6] s;    s = "abc";    writeln(s, s.length);  // abc6, ok it's the static array's length    string t = text("head-", s, "-tail"

Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn
On 02/04/2021 5:32 PM, mw wrote: --- import std; import std.conv : text; void main() {    char[6] s;    s = "abc";    writeln(s, s.length);  // abc6, ok it's the static array's length    string t = text("head-", s, "-tail");    writeln(t, t.length);  // head-abc-tail16, why? assert(t[9]

what exactly is string length?

2021-04-01 Thread mw via Digitalmars-d-learn
https://run.dlang.io/is/B4jcno --- import std; import std.conv : text; void main() { char[6] s; s = "abc"; writeln(s, s.length); // abc6, ok it's the static array's length string t = text("head-", s, "-tail"); writeln(t, t.length); // head-abc-tail16, why? } --- Why th