Charles Baldo
asked on
Need to pad string
Hi
I have a string say s="99"; I need to pad it left with blanks or characters so I need
s to have the value " 99" for a 4 charcter space pad or "--99" to pad with hyphens. Do not want to write a method. is there any way in String.Format?
thanks
chuck
I have a string say s="99"; I need to pad it left with blanks or characters so I need
s to have the value " 99" for a 4 charcter space pad or "--99" to pad with hyphens. Do not want to write a method. is there any way in String.Format?
thanks
chuck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry you'll need single quotes.
s = s.PadLeft(4, "-");
Hi charlesbaldo;
This String.Format in the code below will format "99" to be " 99".
String testString = "99";
MessageBox.Show(String.For mat("The value{0,4} has a length of 4 with 2 spaces before the value", testString));
Fernando
This String.Format in the code below will format "99" to be " 99".
String testString = "99";
MessageBox.Show(String.For
Fernando
ASKER
Thanks a ton the single quotes did it.
ASKER
Thank You