Thread overview
concatenating char's with char arrays
Oct 23, 2003
Charles Sanders
Oct 23, 2003
Helmut Leitner
Oct 23, 2003
Sean L. Palmer
Oct 23, 2003
Vathix
Oct 23, 2003
Hauke Duden
Oct 23, 2003
Nicolas Repiquet
October 23, 2003
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

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
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
"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
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
"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