Home All Groups Group Topic Archive Search About

how to use padright padleft to format text for display?

Author
21 Dec 2006 7:36 PM
Rich
Greetings,

I need to format some text that I display in the output window.  I need to
show something like this:

*abcdef              *
*abcdefghij         *

Here is the code that I try, but ...

str1 =  "abcdef"
Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")

str1 = "abcdefghij"
Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")

the output window displays:

*abcdef*
*abcdefghij*

how do I make it display like this?

*abcdef              *
*abcdefghij         *

Thanks,
Rich

Author
21 Dec 2006 8:08 PM
md
A quick look at the help for PadRight says the parameter is the total
length, so use PadRight(20)

Show quoteHide quote
"Rich" <R***@discussions.microsoft.com> wrote in message
news:F0B07FD5-952C-4E8C-8587-9EE9F6DA5C6A@microsoft.com...
> Greetings,
>
> I need to format some text that I display in the output window.  I need to
> show something like this:
>
> *abcdef              *
> *abcdefghij         *
>
> Here is the code that I try, but ...
>
> str1 =  "abcdef"
> Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")
>
> str1 = "abcdefghij"
> Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")
>
> the output window displays:
>
> *abcdef*
> *abcdefghij*
>
> how do I make it display like this?
>
> *abcdef              *
> *abcdefghij         *
>
> Thanks,
> Rich
Author
21 Dec 2006 8:28 PM
Rich
Thanks.  That did the trick.

Rich

Show quoteHide quote
"md" wrote:

> A quick look at the help for PadRight says the parameter is the total
> length, so use PadRight(20)
>
> "Rich" <R***@discussions.microsoft.com> wrote in message
> news:F0B07FD5-952C-4E8C-8587-9EE9F6DA5C6A@microsoft.com...
> > Greetings,
> >
> > I need to format some text that I display in the output window.  I need to
> > show something like this:
> >
> > *abcdef              *
> > *abcdefghij         *
> >
> > Here is the code that I try, but ...
> >
> > str1 =  "abcdef"
> > Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")
> >
> > str1 = "abcdefghij"
> > Console.WriteLine("*" & str1.PadRight(20 - str1.Length) & "*")
> >
> > the output window displays:
> >
> > *abcdef*
> > *abcdefghij*
> >
> > how do I make it display like this?
> >
> > *abcdef              *
> > *abcdefghij         *
> >
> > Thanks,
> > Rich
>
>
>