Thread overview
what's the proper way to convert wchar[] to string?
Jan 03, 2018
Marc
Jan 03, 2018
Ali Çehreli
Jan 03, 2018
Marc
January 03, 2018
when calling winapi functions, usually you to deal with the result in wchar[]. How do I convert it to string in D to be usable by the application? does D have a native for this?
January 03, 2018
On 01/03/2018 10:50 AM, Marc wrote:
> when calling winapi functions, usually you to deal with the result in wchar[]. How do I convert it to string in D to be usable by the application? does D have a native for this?

std.conv has to and text:

    auto s0 = w.text;
    auto s1 = w.to!string;

Ali
January 03, 2018
On Wednesday, 3 January 2018 at 18:59:39 UTC, Ali Çehreli wrote:
> On 01/03/2018 10:50 AM, Marc wrote:
>> when calling winapi functions, usually you to deal with the result in wchar[]. How do I convert it to string in D to be usable by the application? does D have a native for this?
>
> std.conv has to and text:
>
>     auto s0 = w.text;
>     auto s1 = w.to!string;
>
> Ali

whoa, that simple. I've tried to!string(w) before, but I realized the mistake I was passing the whole buffer rather:

> string s = w[0 .. wcslen(w.ptr)].to!string;

Thanks.