www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Appending Arrays

reply Trevor Parscal <trevorparscal hotmail.com> writes:
I know that the ~ is the greatest things since sliced arrays [ .. ] :)

But when it comes to appending an array with a new element, I am feeling 
like I must be missing something..

Example:

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

// Wont work?
word ~ letter;

// Works fine...
word.length = word.length + 1;
word[word.length - 1] = letter;

Why is this so complex to do? Is there a way I didn't learn from the D 
language docs?

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal hotmail.com
May 31 2005
next sibling parent "John C" <johnch_atms hotmail.com> writes:
"Trevor Parscal" <trevorparscal hotmail.com> wrote in message 
news:d7hq0e$1qgp$1 digitaldaemon.com...
I know that the ~ is the greatest things since sliced arrays [ .. ] :)

 But when it comes to appending an array with a new element, I am feeling 
 like I must be missing something..

 Example:

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

 // Wont work?
 word ~ letter;
Try word ~= letter;
 // Works fine...
 word.length = word.length + 1;
 word[word.length - 1] = letter;

 Why is this so complex to do? Is there a way I didn't learn from the D 
 language docs?

 -- 
 Thanks,
 Trevor Parscal
 www.trevorparscal.com
 trevorparscal hotmail.com 
May 31 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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.
May 31 2005
parent Trevor Parscal <trevorparscal hotmail.com> writes:
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.
Thank you, thank you, thank you, thank you.... Just what i always dreamed of, just one update away.. Walter = the man! -- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.com
May 31 2005