www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - convert string to wchar[]

reply Dr.No <jckj33 gmail.com> writes:
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);
May 26 2018
parent Neia Neutuladh <neia ikeran.org> writes:
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); }
May 26 2018