'Pad a text with a selected character
'psText: Original text
'psCharacter: Padding character. If passed an empty string, a blank space will be used
'pnNewLength: Length of resulting text
'<code>
'PadText("Test", "-", 10, True) 'Result: "------Test"
'PadText("Test", "-", 10, False) 'Result: "Test------"
'</code>
Sub PadText(psText As String, psCharacter As String, pnNewLength As Int, pbLeading As Boolean) As String
Dim cCharacter As Char = " "
Dim sb As StringBuilder
Try
If psCharacter <> "" Then
cCharacter = psCharacter.CharAt(0)
End If
Catch
cCharacter = " " ' default character: space
End Try
sb.Initialize
If pbLeading Then
For nI = 1 To pnNewLength - psText.Length
sb.Append(cCharacter)
Next
sb.Append(psText)
Else
sb.Append(psText)
For nI = 1 To pnNewLength - psText.Length
sb.Append(cCharacter)
Next
End If
Return sb.ToString
End Sub PadText