Solved

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

Posted on 2011-02-27
3
541 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
[X]
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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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