PadLeft

In c# I have the code as follows:
reqn = Session["Reqnumber"].ToString();
reqn = reqn.PadLeft(15,'-');
The value of reqn is never right justified. Please help me.
Thanks
miyengarAsked:
Who is Participating?
 
iboutchkineConnect With a Mentor Commented:
Did you check your session value?
0
 
iboutchkineCommented:
I thiink you have to assign it to different variable
dim a as string
a= reqn.PadLeft(15,'-');
regn = a
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This worked for me in VB.Net (notice the double quotation marks):

    Dim reqn As String = "something"
    reqn = reqn.PadLeft(15, "-")
    MsgBox(reqn)

~IM
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
miyengarAuthor Commented:
It does not work. any other soln
0
 
miyengarAuthor Commented:
reqn = Session["Reqnumber"].ToString();
a = reqn.PadLeft(15,'-');
It returns the value of a as null. Please tell me why?
0
 
miyengarAuthor Commented:
my session value and reqn contains the actual value "wq-01".but "a" still has null
0
 
miyengarAuthor Commented:
It does not work properly i have my code as follows:
                           
            private void Page_Load(object sender, System.EventArgs e)
            {
                  
                       string r;
                  string reqn;
                  string rqtextid;
                  reqn = Session["Reqnumber"].ToString();
                  r = reqn.PadLeft(9,'.');
                  rqtextid = r;
my session value has valid value iii0, reqn also has the same value iii0. but r has null.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Did you actually try it with double quotes?

    r = reqn.PadLeft(9,".");
0
 
miyengarAuthor Commented:
using double quotes gives me an error as no overload method as it accepts int and char.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
How odd...it works in VB.Net.  Thought it was supposed to be a "common" language runtime...

~IM
0
 
miyengarAuthor Commented:
any other suggestion please
I have the code as
  private void Page_Load(object sender, System.EventArgs e)
          {
               
                     string r;
               string reqn;
               string rqtextid;
               reqn = Session["Reqnumber"].ToString();
               r = reqn.PadLeft(9,'.');
               rqtextid = r;

in the above code r has ----wq001 but in the statement rqtextid  = r, rqtextid  has null.
Please help.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Have you tried going directly to rqtextid?

    rqtextid = Session["Reqnumber"].ToString().PadLeft(9,'.');

~IM
0
 
miyengarAuthor Commented:
I did.  If I have to add text further after rightjustifying it would display null
for ex:
rqtextid = Session["Reqnumber"].ToString().PadLeft(9,'.');
rqtextid += "kkk";
would return rqtextid as null
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.