Yes: cast(wchar[]) "string"
I know, I know... :-)
There has been a suggestion to bring back the
C syntax for declaring wide strings: L"string"
(would be the same as: cast(wchar[]) "string")
Or maybe another letter, like w"string" perhaps?
But so far it hasn't been popular... (with W)
BTW;
wchar[] s = "string"; // works without cast()
--anders

Yes. But it's not neat or intuitive given that syntax is available for
writing 'wide' integers and floating point values.
cast(wchar[])"This is a Wide String Literal";
But please beware of a syntactical anomaly; you cannot do this to char[]
variables and get a wchar[].
char[] A = "An ASCII string";
wchar[] W;
W = cast(wchar[])A; // WRONG!
This time the cast makes 'W' point to A's data and has D pretending it is a
wide string, but no data conversion has actually happened.
W = std.utf.toUTF16(A); // CORRECT!
This is the correct way to convert narrow string variables to wide strings.
So to summarize, use 'cast(wchar[])' on narrow string literals and
'std.utf.toUTF16()' on narrow string variables.
Why Walters isn't interested in adding a qualifier on string literals such
as he has for numbers is hard for me to understand.
--
Derek Parnell
Melbourne, Australia
http://www.dsource.org/projects/build v2.06 is now available. 04/May/2005
7/05/2005 7:55:33 PM

But please beware of a syntactical anomaly; you cannot do this to char[]
variables and get a wchar[].
char[] A = "An ASCII string";
wchar[] W;
W = cast(wchar[])A; // WRONG!
This time the cast makes 'W' point to A's data and has D pretending it is a
wide string, but no data conversion has actually happened.
W = std.utf.toUTF16(A); // CORRECT!
This is the correct way to convert narrow string variables to wide strings.

You can also do this: (but only with literals)
char[] A = "An ASCII string";
wchar[] W = "An ASCII string";
char[] A = "A non-ASCII string (€)";
wchar[] W = "A non-ASCII string (€)";
And the same goes for non-literal conversions:
A = cast(char[]) W; // WRONG
A = std.utf.toUTF8(W); // CORRECT
Note:
Sometimes you have to cast "" into char[], like if you
have a function overloaded with both char[] and wchar[] ?
(Phobos uses a "W" prefix/suffix on wchar[] functions...)
The string literals in D are of an *unnamed* string type.
They are not of the type "char[]", like one might expect...
(since e.g. the integer and floating literals are typed ?)
--anders