fromStringz

  1. inout(Char)[] fromStringz(inout(Char)* cString)
  2. inout(Char)[] fromStringz(inout(Char)[] cString)
    @nogc @safe pure nothrow
    inout(Char)[]
    fromStringz
    (
    Char
    )
    (
    return scope inout(Char)[] cString
    )
    if ()

Parameters

cString inout(Char)[]

A null-terminated c-style string.

Return Value

Type: inout(Char)[]

A D-style array of char, wchar or dchar referencing the same string. The returned array will retain the same type qualifiers as the input.

Important Note: The returned array is a slice of the original buffer. The original data is not changed and not copied.

Examples

assert(fromStringz("foo\0"c.ptr) == "foo"c);
assert(fromStringz("foo\0"w.ptr) == "foo"w);
assert(fromStringz("foo\0"d.ptr) == "foo"d);

assert(fromStringz("福\0"c.ptr) == "福"c);
assert(fromStringz("福\0"w.ptr) == "福"w);
assert(fromStringz("福\0"d.ptr) == "福"d);
struct C
{
    char[32] name;
}
assert(C("foo\0"c).name.fromStringz() == "foo"c);

struct W
{
    wchar[32] name;
}
assert(W("foo\0"w).name.fromStringz() == "foo"w);

struct D
{
    dchar[32] name;
}
assert(D("foo\0"d).name.fromStringz() == "foo"d);

Meta