View source code
Display the source code in std/string.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.string.toStringz
Prototypes
immutable(char)* toStringz( const(char)[] s ) pure nothrow @trusted; immutable(char)* toStringz( const(string) s ) pure nothrow @trusted;
Parameters
Name | Description |
---|---|
s | A D-style string. |
Returns
A C-style null-terminated string equivalent to
. s
must not contain embedded s
'\0'
's
as any C function will treat the
first '\0'
that it sees as the end of the string. If s.empty
is
true
, then a string containing only '\0'
is returned.
Important Note: When passing a char*
to a C function, and the C
function keeps it around for any reason, make sure that you keep a
reference to it in your D code. Otherwise, it may become invalid during a
garbage collection cycle and cause a nasty bug when the C code tries to use
it.
Authors
Walter Bright, Andrei Alexandrescu, and Jonathan M Davis