VB.NET Padding Strings

Padding String, Padding String in VB.NET
  • 8757

The PadLeft and PadRight methods can be used to pad strings. The PadLeft method right-aligns and pads a string so that its rightmost character is the specified distance from the beginning of the string. The PadRight method left-aligns and pads a string so that its rightmost character is a specified distance from the end of the string. These methods return new String objects that can either be padded with empty spaces or with custom characters. Listign 3 shows how to use these methods.

Listing 3: Using padding methods

    Module Module1
        Sub Main()
            Dim str1 As String = "My String"
            Console.WriteLine(str1.PadLeft(20, "-"c))
            Dim str2 As String = "My String"
            Console.WriteLine(str2.PadRight(20, "-"c))
            Console.ReadLine()
        End Sub
    End
Module

The output of Listing 3 is shown in Figure given below:

Padd1.gif 

Conclusion


Hope this article would have helped you in understanding Padding String in VB.NET.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.