Padding Strings.
PadRight and PadLeft string with vb,net
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.
Dim strOutput As String
Dim str1 As String = "My String"
strOutput = (str1.PadLeft(20, "-"))
Dim str2 As String = "My String"
strOutput = (str2.PadRight(20, "-"))
===================================
Output
-------------------My String
My String-------------------
================================
No comments:
Post a Comment