www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - cstrings

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
are there any other cstring -> dstring functions than to!string(char*) ?

something like to!(char[])(char*)

(the memory allocation bothers me)
Jan 01 2011
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday 01 January 2011 20:12:31 Ellery Newcomer wrote:
 are there any other cstring -> dstring functions than to!string(char*) ?
 
 something like to!(char[])(char*)
 
 (the memory allocation bothers me)
to!(char[])() should work just fine, but I believe that you're going to have to have a memory allocation regardless, since a D array can't refer to an arbitrary pointer. A D array and a C/C++ array are two different different things, even though a D array uses a C/C++ array internally. A D array is able to be resized and reallocated and the like in a way that a C/C++ array can't be. - Jonathan M Davis
Jan 02 2011
prev sibling parent Mafi <mafi example.org> writes:
Am 02.01.2011 05:12, schrieb Ellery Newcomer:
 are there any other cstring -> dstring functions than to!string(char*) ?

 something like to!(char[])(char*)

 (the memory allocation bothers me)
You can simply make a slice. Indexing and sclicing works also with c-style pointers in D. Obviously $ is not allowed because bare pointers don't have a length. poinetr[0 .. strlen(pointer)] Be sure to not give this array to functions which relies on your char[] to be GC-allocated.
Jan 02 2011