On 07.12.22 01:35, ryuukk_ wrote:
On Tuesday, 6 December 2022 at 23:41:09 UTC, H. S. Teoh wrote:
[...]
In D, strings are not the same as char*.  You should use std.conv.fromStringZ to convert the C char* to a D string.
[...]
no, you don't "need" to use std conv


Here is an alternative that doesn't allocate
[...]
    // now we got a len, we can build a D string, remember, it's just a slice

     string str = cast(string) ret[0 .. len];

Slicing is exactly what std.string.fromStringz does.

<https://dlang.org/phobos/std_string.html#.fromStringz>:
"The returned array is a slice of the original buffer. The original data is not changed and not copied."

Reply via email to