On Monday, 25 July 2022 at 11:14:56 UTC, pascal111 wrote:
module main;

import std.stdio;
import core.stdc.stdio;
import core.stdc.string;

int main(string[] args)
{


        const(char)[] ch1 = "Hello World!";
        char[] ch2="Hello World!".dup;

        const(char) *p1;
        char *p2;

        p1=ch1.ptr;
        p2=ch2.ptr;

        writeln(p1[0..strlen(p1)]);
        writeln(p2[0..strlen(p2)]);

        return 0;
    }


Runtime output:

https://i.postimg.cc/sfnkJ4GM/Screenshot-from-2022-07-25-13-12-03.png

Do not post screenshots of text.

`strlen` only works on null-terminated strings. The result of `.dup` is not null-terminated, so `strlen` doesn't work on it.

Reply via email to