www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I create a char[] from a const(char)[]?

reply Dan <murpsoft hotmail.com> writes:
I have a const(char)[] string being passed in as a parameter (can't change
that) and I want to create a duplicate that is not const.

I tried all manner of things that would make sense to dispose of the constness
of it.  It's looking though that I will have to actually loop through and cast
every freaking character?

void myfunc(const(char)[] sin){
  char[] sout = cast(char[]) sin; // nope
  char[] sout = cast(char[]) sin.dup; // nope
  char[] sout = (cast(char[]) sin).dup; // nope

What's the trick?
Dec 22 2007
parent Derek Parnell <derek psych.ward> writes:
On Sat, 22 Dec 2007 18:35:26 -0500, Dan wrote:

 I have a const(char)[] string being passed in as a parameter (can't change
that) and I want to create a duplicate that is not const.
 
 I tried all manner of things that would make sense to dispose of the constness
of it.  It's looking though that I will have to actually loop through and cast
every freaking character?
 
 void myfunc(const(char)[] sin){
   char[] sout = cast(char[]) sin; // nope
   char[] sout = cast(char[]) sin.dup; // nope
   char[] sout = (cast(char[]) sin).dup; // nope
 
 What's the trick?

I just use ... char[] sout = sin.dup; What version of D are you trying this with? -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Dec 22 2007