Padding operations of string in


Padding a string adds whitespace or other characters to the beginning or end. In string Class there are two padding methods-
1. PadLeft
2. PadRight

The PadLeft and PadRight methods in C# can also be used to insert characters. But these are used to add characters to the beginning and end of your text.

String Class has two functions for PadLeft and PadRight both.

str.PadLeft(totalWidth as Integer)
str.PadLeft(totalWidth as Integer,PaddingChar as Char)
str.PadRight(totalWidth as Integer)
str.PadRight(totalWidth as Integer,PaddingChar as Char)

if we use PadLeft or PadRight without PaddingChar then it will automatically add whitespace and complete string length.


Dim str As String
str = "ABCDE"
str = str.PadLeft(8)
str = str.PadLeft(8, ".")

str = str.PadRight(8)
str = str.PadRight(8, ".")



…ABCDE      // three whitespace at left


ABCDE…     // three whitespace at Right