Solved

PadRight is not adding space to the end of the variable using C#.net

Posted on 2011-02-27
3
532 Views
Last Modified: 2012-05-11
I am trying to format some text using the .padright(#) command but the command is not adding the additional space at the end of the text.  Can someone show me where I may be going wrong?

When I debug the code the contents of the variable is

"Lunesta 3 mg Tab"

instead of

"Lunesta 3 mg Tab    "
firsttab = 20;
                    if (rsdatarec.rxdata.RxItemName == null)
                    {
                        RxItemNameLen = 0;
                        fmtRxITemName = "                    ";
                    }
                    else
                    {
                        RxItemNameLen = rsdatarec.rxdata.RxItemName.Length;
                        firstpad = firsttab - RxItemNameLen;
                        fmtRxITemName = rsdatarec.rxdata.RxItemName.PadRight(firstpad);
                        
                    }

Open in new window

0
Comment
Question by:kwh3856
3 Comments
 
LVL 10

Accepted Solution

by:
eguilherme earned 500 total points
ID: 34992440
you should do

 fmtRxITemName = rsdatarec.rxdata.RxItemName.PadRight(20);

there is no need to do
firstpad = firsttab - RxItemNameLen;

0
 

Author Closing Comment

by:kwh3856
ID: 34992477
Thank you.  That was it.
0
 
LVL 5

Expert Comment

by:MikkelAStrojek
ID: 34992493
fmtRxITemName = rsdatarec.rxdata.RxItemName.PadRight(rsdatarec.rxdata.RxItemName.length+1);

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question