Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

printing n spaces

Okay, this has been bugging the heck out of me: Is there something akin to
a space(n) or repeat(char, n) function that would allow me to print out a
number of spaces on Console? I'm toying around with XML, and having an
indented tree view is infinitely less confusing than a flat printout. Using
a loop to print spaces for indentation, though, is a little... less than
aesthetically pleasing... to say the least. Actually, it makes me feel like
throwing up, so if you've got a solution, please write me!
[540 byte] By [Oscar] at [2007-11-9 18:21:40]
# 1 Re: printing n spaces
We don't support the Perl "x" operator, and I don't know of any built-in to
do what you want.

I do know, however, that some of the XML stuff lets you set the indent; it
might be easier to go that route.

"Oscar" <consulBanana@hotmail.com> wrote in message
news:399c18c2$1@news.dev-archive.com...
> Okay, this has been bugging the heck out of me: Is there something akin
to
> a space(n) or repeat(char, n) function that would allow me to print out a
> number of spaces on Console? I'm toying around with XML, and having an
> indented tree view is infinitely less confusing than a flat printout.
Using
> a loop to print spaces for indentation, though, is a little... less than
> aesthetically pleasing... to say the least. Actually, it makes me feel
like
> throwing up, so if you've got a solution, please write me!
>
>
Eric Gunnerson at 2007-11-11 22:29:11 >
# 2 Re: printing n spaces
The String class has a (char c, int count) constructor which I think will do
it.

Oscar <consulBanana@hotmail.com> wrote in message
news:399c18c2$1@news.dev-archive.com...
> Okay, this has been bugging the heck out of me: Is there something akin
to
> a space(n) or repeat(char, n) function that would allow me to print out a
> number of spaces on Console? I'm toying around with XML, and having an
> indented tree view is infinitely less confusing than a flat printout.
Using
> a loop to print spaces for indentation, though, is a little... less than
> aesthetically pleasing... to say the least. Actually, it makes me feel
like
> throwing up, so if you've got a solution, please write me!
>
>
David Bayley at 2007-11-11 22:30:16 >
# 3 Re: printing n spaces
I tried that one before, but it doesn't seem to recognize that constructor.
Says (string, string) is the closest thing it's got. Maybe I need to
include System.String.Constructors(char[],int).dll

"David Bayley" <dbayley@aebacus.com> wrote in message
news:399c2312@news.dev-archive.com...
> The String class has a (char c, int count) constructor which I think will
do
> it.
>
> Oscar <consulBanana@hotmail.com> wrote in message
> news:399c18c2$1@news.dev-archive.com...
> > Okay, this has been bugging the heck out of me: Is there something akin
> to
> > a space(n) or repeat(char, n) function that would allow me to print out
a
> > number of spaces on Console? I'm toying around with XML, and having an
> > indented tree view is infinitely less confusing than a flat printout.
> Using
> > a loop to print spaces for indentation, though, is a little... less than
> > aesthetically pleasing... to say the least. Actually, it makes me feel
> like
> > throwing up, so if you've got a solution, please write me!
> >
> >
>
>
Oscar at 2007-11-11 22:31:20 >
# 4 Re: printing n spaces
Come to think of it, the (string, string) constructor that it thinks it
needs to use doesn't seem to be in the docs.

"David Bayley" <dbayley@aebacus.com> wrote in message
news:399c2312@news.dev-archive.com...
> The String class has a (char c, int count) constructor which I think will
do
> it.
>
> Oscar <consulBanana@hotmail.com> wrote in message
> news:399c18c2$1@news.dev-archive.com...
> > Okay, this has been bugging the heck out of me: Is there something akin
> to
> > a space(n) or repeat(char, n) function that would allow me to print out
a
> > number of spaces on Console? I'm toying around with XML, and having an
> > indented tree view is infinitely less confusing than a flat printout.
> Using
> > a loop to print spaces for indentation, though, is a little... less than
> > aesthetically pleasing... to say the least. Actually, it makes me feel
> like
> > throwing up, so if you've got a solution, please write me!
> >
> >
>
>
Oscar at 2007-11-11 22:32:19 >
# 5 Re: printing n spaces
I haven't got a spare machine to trash, so I'm just reading the docs.

If you're using <c>new String(' ', n)</c>, then perhaps the compiler is
treating the first param as a String rather than a char, and getting
confused with the (String) constructor.

One of the following...

new String((char)' ', n)
new String((char)32, n)
new String(Char.FromString(' '), n)

...might work?

Regards, David.

Oscar <consulBanana@hotmail.com> wrote in message
news:399ca41b$1@news.dev-archive.com...
> Come to think of it, the (string, string) constructor that it thinks it
> needs to use doesn't seem to be in the docs.
>
> "David Bayley" <dbayley@aebacus.com> wrote in message
> news:399c2312@news.dev-archive.com...
> > The String class has a (char c, int count) constructor which I think
will
> do
> > it.
> >
> > Oscar <consulBanana@hotmail.com> wrote in message
> > news:399c18c2$1@news.dev-archive.com...
> > > Okay, this has been bugging the heck out of me: Is there something
akin
> > to
> > > a space(n) or repeat(char, n) function that would allow me to print
out
> a
> > > number of spaces on Console? I'm toying around with XML, and having
an
> > > indented tree view is infinitely less confusing than a flat printout.
> > Using
> > > a loop to print spaces for indentation, though, is a little... less
than
> > > aesthetically pleasing... to say the least. Actually, it makes me
feel
> > like
> > > throwing up, so if you've got a solution, please write me!
> > >
> > >
> >
> >
>
>
David Bayley at 2007-11-11 22:33:24 >
# 6 Re: printing n spaces
Problem solved! You were definitely right: the compiler was treating the
first param as a string, but the culprit appears to have been my use of "c"
rather than 'c'. This confirms my theory that extended periods of exposure
to VBScript can actually cause damage to programming skills. :(

Thanks very much,
Oscar

"David Bayley" <dbayley@aebacus.com> wrote in message
news:399d2966@news.dev-archive.com...
> I haven't got a spare machine to trash, so I'm just reading the docs.
>
> If you're using <c>new String(' ', n)</c>, then perhaps the compiler is
> treating the first param as a String rather than a char, and getting
> confused with the (String) constructor.
>
> One of the following...
>
> new String((char)' ', n)
> new String((char)32, n)
> new String(Char.FromString(' '), n)
>
> ...might work?
>
> Regards, David.
>
> Oscar <consulBanana@hotmail.com> wrote in message
> news:399ca41b$1@news.dev-archive.com...
> > Come to think of it, the (string, string) constructor that it thinks it
> > needs to use doesn't seem to be in the docs.
> >
> > "David Bayley" <dbayley@aebacus.com> wrote in message
> > news:399c2312@news.dev-archive.com...
> > > The String class has a (char c, int count) constructor which I think
> will
> > do
> > > it.
> > >
> > > Oscar <consulBanana@hotmail.com> wrote in message
> > > news:399c18c2$1@news.dev-archive.com...
> > > > Okay, this has been bugging the heck out of me: Is there something
> akin
> > > to
> > > > a space(n) or repeat(char, n) function that would allow me to print
> out
> > a
> > > > number of spaces on Console? I'm toying around with XML, and having
> an
> > > > indented tree view is infinitely less confusing than a flat
printout.
> > > Using
> > > > a loop to print spaces for indentation, though, is a little... less
> than
> > > > aesthetically pleasing... to say the least. Actually, it makes me
> feel
> > > like
> > > > throwing up, so if you've got a solution, please write me!
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Oscar at 2007-11-11 22:34:16 >