Padding operations of string in vb.net

Padding

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.

Example

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

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

Output:

ABCDE

…ABCDE      // three whitespace at left

ABCDE

ABCDE…     // three whitespace at Right