How to ensure string compatibility In D?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Tue Jan 22 19:14:43 UTC 2019
On Tuesday, January 22, 2019 12:05:32 PM MST Stefan Koch via Digitalmars-d-
learn wrote:
> On Tuesday, 22 January 2019 at 16:47:45 UTC, FrankLike wrote:
> > On Tuesday, 22 January 2019 at 16:18:17 UTC, Adam D. Ruppe
> >
> > wrote:
> >> Use "mystring"w, notice the w after the closing quote.
> >
> > Or toStringz is not work like c_str() in C++?
>
> stringz creates a char*
> but you need a wchar*
std.utf.toUTF16z or toUTFz can do that for you, though if your string is
already a wstring, then you can also just concatenate '\0' to it. the big
advantage toUTF16z is that it will also convert strings of other character
types rather than just wstrings. So, you can write your program using proper
UTF-8 strings and then only convert to UTF-16 for the Windows stuff when you
have to.
https://dlang.org/phobos/std_utf.html#toUTF16z
https://dlang.org/phobos/std_utf.html#toUTFz
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list