Thread overview
constructing char[] variables
Mar 15, 2004
Andrew Edwards
Mar 15, 2004
Phill
Mar 15, 2004
Vathix
Mar 15, 2004
J Anderson
March 15, 2004
Give the following:

char[] str;
for(int i = 0; i < 50; i++)
  str ~= "*";

is there another way to accomplish this in D?
In C++ I would simply:

std::string str(50, '*');

TIA,
Andrew
-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
March 15, 2004
You can do it this way as well although
it is probably more hassle:

char[] another ;

    for(int i = 0; i < 50; i++)
    {
        another.length = i + 1;
     strcat(another, "*");
     }

You would need to :

import std.string;

Phill.


"Andrew Edwards" <remove_ridimz@remove_yahoo.com> wrote in message news:opr4v5dnvus6zaqn@news.digitalmars.com...
> Give the following:
>
> char[] str;
> for(int i = 0; i < 50; i++)
>    str ~= "*";
>
> is there another way to accomplish this in D?
> In C++ I would simply:
>
> std::string str(50, '*');
>
> TIA,
> Andrew
> --
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


March 15, 2004
Andrew Edwards wrote:
> Give the following:
> 
> char[] str;
> for(int i = 0; i < 50; i++)
>   str ~= "*";
> 
> is there another way to accomplish this in D?
> In C++ I would simply:
> 
> std::string str(50, '*');
> 
> TIA,
> Andrew

char[] str = new char[50];
str[] = '*';


-- 
Christopher E. Miller
March 15, 2004
Andrew Edwards wrote:

> Give the following:
>
> char[] str;
> for(int i = 0; i < 50; i++)
>   str ~= "*";
>
>
Just a small quibble with this code:
   char[] str;
   str.length = 50; //Initialize size first
   foreach(inout char c; str)
       c = '*';

> is there another way to accomplish this in D?
> In C++ I would simply:
>
> std::string str(50, '*');

Make your own function to do this.

-- 
-Anderson: http://badmama.com.au/~anderson/