|
|
Title | Pad strings on the left or right in Visual Basic .NET |
Description | This example shows how to use the RtlMoveMemory API function to copy part of a two-dimensional array into a one-dimensional array in Visual Basic .NET. |
Keywords | pad string, PadLeft, PadRight, String, format string, VB .NET |
Categories | VB.NET, Strings |
|
|
Use the String class's PadLeft and PadRight methods to pad a string to a given length. The following code returns results similar to the following:
| Left|
|Right |
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim txt As String = ""
txt &= "|" & "Left".PadLeft(8) & "|" & vbCrLf
txt &= "|" & "Right".PadRight(8) & "|" & vbCrLf
txtResult.Text = txt
txtResult.Select(0, 0)
End Sub
|
|
|
|
|
|