?
Solved

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

Posted on 2011-02-27
3
Medium Priority
?
549 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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