I don't know if it does this, but immutable could avoid copying: string a = "hello\0"; auto c_str = toStringz(a); assert(c_str is a.ptr); // it already fit the bill so no change needed