xarraydup

Makes a null-terminated copy of the given string on newly allocated memory. The null-terminator won't be part of the returned string slice. It will be at position n where n is the length of the input string.

extern (D) pure nothrow
char[]
xarraydup
(
const(char)[] s
)

Parameters

s const(char)[]

string to copy

Return Value

Type: char[]

A null-terminated copy of the input array.

Examples

auto s1 = "foo";
auto s2 = s1.xarraydup;
s2[0] = 'b';
assert(s1 == "foo");
assert(s2 == "boo");
assert(*(s2.ptr + s2.length) == '\0');
string sEmpty;
assert(sEmpty.xarraydup is null);

Meta