Padding a String

To pad a string to a certain length, we can use the PadLeft and PadRight methods of the String class.

String.PadLeft Method (Int32) 

String.PadLeft Method (Int32, Char)

String.PadRight Method (Int32)

String.PadRight Method (Int32, Char)

For example:

myString = “123”.PadLeft(6, “0”c)

will return “000123”.

Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: