Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 36
Set form below another form 3 26
Create XML 5 34
Iterate two lists and remove inactive 11 38
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now