Advertisement
7_2009-2012 String Manipulation #228130

PadString Any Side

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.

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
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
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine