Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of openshac
openshac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of openshac
openshac

Sorry you'll need single quotes.
s = s.PadLeft(4, "-");
Avatar of Fernando Soto
Hi charlesbaldo;

This String.Format in the code below will format "99" to be "  99".

String testString = "99";

MessageBox.Show(String.Format("The value{0,4} has a length of 4 with 2 spaces before the value", testString));

Fernando




Avatar of Charles Baldo

ASKER

Thanks a ton the single quotes did it.
Thank You