CorString: PadRight

PadRight

Returns a new string that left-aligns the characters in this string by padding them on the right with a specified Unicode character, for a specified total length.



 Public Function PadRight(
	  ByRef s As String,
	  ByVal TotalWidth As Long,
	  Optional ByRef PaddingChar As Variant = 32 ) As String

Parameters

s
[ByRef] String. The string to be padded.
TotalWidth
[ByVal] Long. The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.
PaddingChar
[ByRef] Optional. Variant. A Unicode padding character. AscW and Chrw$ values are accepted.  

Default: 32

Return Values

String -  A new string that is equivalent to s, but left-aligned and padded on the right with as many PaddingChar characters as needed to create a length of TotalWidth. However, if TotalWidth is less than the length of s, the method returns s. If TotalWidth is equal to the length of s, the method returns a new string that is identical to s.

Remarks

The PadRight(String,Int32, Char) method pads the end of the returned string.

PaddingChar can accept either AscW or ChrW$ values.

Note This method does not modify the s parameter. Instead, it returns a new string that is padded with trailing PaddingChar characters so that its total length is TotalWidth characters.

Exceptions

ExceptionCondition
ArgumentOutOfRangeException TotalWidth is less than zero.

Examples

The following example demonstrates the PadRight method.

Public Sub Main()
    Const Str As String = "Forty-Two"
    Const StrPad As String = "."
    Const CharPad As Integer = 46
    
    Debug.Print CorString.PadRight(Str, 15, StrPad)
    Debug.Print CorString.PadRight(Str, 15, CharPad)
    Debug.Print CorString.PadRight(Str, 2, StrPad)
End Sub

' The previous code outputs the following.
'
'    Forty-Two......
'    Forty-Two......
'    Forty-Two

See Also

Project CorLib Overview

Class CorString Overview