VB.NET Padding
Padding is used to align the characters to the left and right side on the screen. In simple word you can see it’s used for width between two strings.
Padding is used to align the characters to the left and right side on the screen. In simple word you can say it's used for giving width between two strings. String.PadLeft (integer value) method used to left align strings and String.PadRight (integer value) method used to right align strings. You can add a white space or any other characters in padding string. PadLeft () and PadRight () method can take one or two parameters. In below code I used only one parameter.
Code
Module Module1
Sub Main()
Console.WriteLine("Left Padding")
Console.WriteLine("!" & "Left".PadLeft(10) & "!" & vbLf)
Console.WriteLine("Right Padding")
Console.WriteLine("!" & "Right".PadRight(10) & "!" & vbLf & vbLf)
Console.ReadLine()
End Sub
End Module
Output
Code
Module Module1
Sub Main()
If True Then
Dim i As Integer() = New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Console.Write("S.no".PadRight(15))
Console.Write("Visitor name")
Console.WriteLine()
For Each x As Integer In i
Console.Write(x.ToString().PadRight(15))
Console.ReadLine()
Next
End If
Console.WriteLine(vbLf)
If True Then
Dim i As Integer() = New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Console.Write("S.no")
Console.Write("Visitor name".PadLeft(15))
Console.WriteLine()
Dim s As String() = New String() {"Mark", "Clark", "Hanry", "Sunny", "Ricky", "Hussey", "Lara", "Haden", "Pointing", "Bush"}
For Each x As Integer In i
Console.Write(x.ToString())
Dim y As Integer = x
If True Then
Console.WriteLine(s(y - 1).PadLeft(15))
End If
Next
End If
Console.ReadLine()
End Sub
End Module
Output