VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



PadString Any Side

by VisualProgman (2 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Pads a string with any character you like. I usually use it to pad numbers with leading zeros. But you can use it for other things.

Inputs
Input ltring, length of return string, pad character, and side to pad
Code Returns
a string
Side Effects
No matter howmany characters in the pstrChar your pad character is the first character of pstrChar.
API Declarations
Public Enum enPadString
pdLeft
pdRight
End Enum

Rate PadString Any Side

Public Function PadString(pstrInput As String, _
 pintWidth As Integer, _
 pstrChar As String, _
 Optional penSidetoPad As enPadString = pdLeft) As String
 
 'Returns
 '-------
 'PadString("12345", 10, "0") = "0000012345"
 'PadString("12345", 10, "0", pdRight)) = "1234500000"
 'Declare Variables
 '-----------------
 Dim strTemp As String
 '-----------------
 'End Declares
 
 'Creates a string to the length of
 'pintWidth of the first character
 'of pstrChar.
 strTemp = String$(pintWidth, pstrChar)
 
 'Check to see what side to pad?
 If penSidetoPad = pdRight Then
  PadString = Left$(pstrInput & strTemp, pintWidth)
 Else
  PadString = Right$(strTemp & pstrInput, pintWidth)
 End If
 
End Function 'PadString

Download this snippet    Add to My Saved Code

PadString Any Side Comments

No comments have been posted about PadString Any Side. Why not be the first to post a comment about PadString Any Side.

Post your comment

Subject:
Message:
0/1000 characters