www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - confused about appending arrays...

reply clayasaurus <clayasaurus gmail.com> writes:
In a post a while back ...

Walter wrote:

 "Trevor Parscal" <trevorparscal hotmail.com> wrote in message
 news:d7hq0e$1qgp$1 digitaldaemon.com...

 char[] word = "test";
 char letter = '1';

 // Wont work?
 word ~ letter;
Right, but that's a compiler bug. It'll be fixed in the next update.
Ok. So in the next update, whenever you use char[] array = "some"; array ~ "thing"; writefln(array); <-- will print "something"? I thought you used ~= if you want to add append, and ~ if you just want it to return the appened value. I'm thoroughly confused.
Jun 05 2005
parent Derek Parnell <derek psych.ward> writes:
On Sun, 05 Jun 2005 20:27:49 -0400, clayasaurus wrote:

 In a post a while back ...
 
 Walter wrote:
 
  > "Trevor Parscal" <trevorparscal hotmail.com> wrote in message
  > news:d7hq0e$1qgp$1 digitaldaemon.com...
  >
  >> char[] word = "test";
  >> char letter = '1';
  >>
  >> // Wont work?
  >> word ~ letter;
  >
  >
  >
  > Right, but that's a compiler bug. It'll be fixed in the next update.
  >
 
 Ok. So in the next update, whenever you use
 
 char[] array = "some";
 
 array ~ "thing";
 
 writefln(array); <-- will print "something"?
 
 I thought you used ~= if you want to add append, and ~ if you just want 
 it to return the appened value. I'm thoroughly confused.
I think that Walter was hinting that the concatenate operator will be working on the right hand side of an expression if one (or both?) of the types are the element types. for eaxample: char[] a; char[] b; char c; a = b ~ c; if ( (c ~ a) == testval) . . . Currently, you get the message "array cat with element not implemented" when you try these sort of things. I expect that the next release will implement this obvious usage. -- Derek Melbourne, Australia 6/06/2005 11:53:49 AM
Jun 05 2005