convert string to wchar[]

Neia Neutuladh neia at ikeran.org
Sat May 26 17:37:15 UTC 2018


On Saturday, 26 May 2018 at 17:12:38 UTC, Dr.No wrote:
> What's D's way to do that? I need it to be mutable array of 
> wchar because a Windows function requires that.
>
> Alternative to go down to using pointers, which would be 
> something like:
>
> wchar[] w = new wchar[s.length];
> memcpy(w.ptr, s.ptr, s.length);

std.conv.to has you covered for quite a lot of conversions:

import std.conv;
import std.stdio;
void main()
{
     string s = "hello world";
     wchar[] mutableUtf16 = s.to!(wchar[]);
     mutableUtf16[0] = '☃';
     // prints ☃ello world
     writeln(mutableUtf16);
}



More information about the Digitalmars-d-learn mailing list