Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
October 23, 2003 concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
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 |
October 23, 2003 Re: concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | 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 |
October 23, 2003 Re: concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Helmut Leitner | 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 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"; |
October 23, 2003 Re: concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Helmut Leitner | "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 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 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"; |
October 23, 2003 Re: concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote: >> alias char [] String; >> <snip> >> String s="?"; >> s[0]=c; <snip> > 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? ;) |
October 23, 2003 Re: concatenating char's with char arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | "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 |
Copyright © 1999-2021 by the D Language Foundation