www.digitalmars.com         C & C++   DMDScript  

D - concatenating char's with char arrays

reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Will this ever be possible ?


char [] str = 'A' ~ " string";

( im actually running through a string in a for loop , and it doesnt allow
casting from char to char [] )

C
Oct 22 2003
next sibling parent reply Helmut Leitner <helmut.leitner chello.at> writes:
Charles Sanders wrote:
 
 Will this ever be possible ?
 
 char [] str = 'A' ~ " string";
 
 ( im actually running through a string in a for loop , and it doesnt allow
 casting from char to char [] )

I think all primitives should at least have a toString property. For the Moment you could use a canonical function alias char [] String; String CharRetString(char c) { String s="?"; s[0]=c; return s; } String s= CharRetString('A') ~ "abc"; -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Oct 22 2003
next sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
It seems like converting a basic type like char or int to a slice char[] or
int[] would not only be possible, but cheap as well.  It's a
one-dimensional, single element array!  ;)

Sean

"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3F976AD2.9F703033 chello.at...
 Charles Sanders wrote:
 Will this ever be possible ?

 char [] str = 'A' ~ " string";

 ( im actually running through a string in a for loop , and it doesnt


 casting from char to char [] )

I think all primitives should at least have a toString property. For the Moment you could use a canonical function alias char [] String; String CharRetString(char c) { String s="?"; s[0]=c; return s; } String s= CharRetString('A') ~ "abc";

Oct 23 2003
prev sibling parent reply "Vathix" <vathix dprogramming.com> writes:
"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3F976AD2.9F703033 chello.at...
 Charles Sanders wrote:
 Will this ever be possible ?

 char [] str = 'A' ~ " string";

 ( im actually running through a string in a for loop , and it doesnt


 casting from char to char [] )

I think all primitives should at least have a toString property. For the Moment you could use a canonical function alias char [] String; String CharRetString(char c) { String s="?"; s[0]=c; return s; } String s= CharRetString('A') ~ "abc"; -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com

That code looks bad. Remember we're not supposed to write over string literals; and why the String? Here's what I do: char ch = 'A'; char[] s = (&ch)[0 .. 1] ~ "abc";
Oct 23 2003
parent Hauke Duden <H.NS.Duden gmx.net> writes:
Vathix wrote:
   alias char [] String;


     String s="?";
     s[0]=c;


 That code looks bad. Remember we're not supposed to write over string
 literals;

Have I ever mentioned that I think D needs a true const type modifier? ;)
Oct 23 2003
prev sibling parent "Nicolas Repiquet" <deadcow-remove-this free.fr> writes:
"Charles Sanders" <sanders-consulting comcast.net> a écrit dans le message
news: bn7b4e$1t8o$1 digitaldaemon.com...
 Will this ever be possible ?


 char [] str = 'A' ~ " string";

 ( im actually running through a string in a for loop , and it doesnt allow
 casting from char to char [] )

char [] str = "hell"; str ~= 'o'; this works. char[] str = "hell"; str = str ~ 'o'; this dont. I ask walter for this, and i was answered that it is a bug, and it'll be fixed soon. -- Nicolas Repiquet
Oct 23 2003