Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-02-27
3
533 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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