D - Converting char* to char[]
- Russell Lewis (6/6) Sep 10 2002 What is the proper way to take a char* value (passed from C code) and
- Walter (7/13) Sep 10 2002 Array slicing syntax does the job:
- Pavel Minayev (3/10) Sep 10 2002 Better yet, add another function to string.d.
- Walter (3/13) Sep 10 2002 good idea
What is the proper way to take a char* value (passed from C code) and create a dynamic array from it? Is it possible to do this without making a copy? You could copy it by hand, element by element, but there's got to be a better way (perhaps a cast from char* to char[] would set both the buffer and the length to the right size?). I checked the D spec, and I can't see any reference to it.
Sep 10 2002
"Russell Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3D7E3A0F.4090903 deming-os.org...What is the proper way to take a char* value (passed from C code) and create a dynamic array from it? Is it possible to do this without making a copy? You could copy it by hand, element by element, but there's got to be a better way (perhaps a cast from char* to char[] would set both the buffer and the length to the right size?). I checked the D spec, and I can't see any reference to it.Array slicing syntax does the job: char *foo(); char *p = foo(); char[] b = p[0 .. strlen(p)]; I should add this to the spec.
Sep 10 2002
Walter wrote:Array slicing syntax does the job: char *foo(); char *p = foo(); char[] b = p[0 .. strlen(p)]; I should add this to the spec.Better yet, add another function to string.d. Could be toString(char*).
Sep 10 2002
good idea "Pavel Minayev" <evilone omen.ru> wrote in message news:alljeo$gr7$4 digitaldaemon.com...Walter wrote:Array slicing syntax does the job: char *foo(); char *p = foo(); char[] b = p[0 .. strlen(p)]; I should add this to the spec.Better yet, add another function to string.d. Could be toString(char*).
Sep 10 2002