Using char* and C code

Jonathan M Davis jmdavisProg at gmx.com
Wed Mar 6 23:40:37 PST 2013


On Thursday, March 07, 2013 08:19:57 Jeremy DeHaan wrote:
> > That's what toStringz is for, and it'll avoid appending the
> > '\0' if it can
> > (e.g. if the code unit one past the end of the string is '\0'
> > as it is with
> > string literals).
> 
> I actually have a different question related to this now that I
> think about it. Is there a similar function to go from a '\0'
> terminated char* to a D string? Lately I have been using
> std.conv.text, but I have also made a function that just parses
> the pointer and copies its data into a string. I'm actually kind
> of surprised that there isn't anything built into the string
> class like this.

There is no string class. A string is simply imutable(char)[]. Nothing is 
built into string which isn't built into arrays in general.

But if you want to convert from a char* to string, then just use std.conv.to:

auto str = to!string(ptr);

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list