Skip to content

Planet-Source-Code/visualprogman-padstring-any-side__1-33748

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

PadString Any Side

Description

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.

More Info

Input ltring, length of return string, pad character, and side to pad

a string

No matter howmany characters in the pstrChar your pad character is the first character of pstrChar.

Submitted On
By VisualProgman
Level Beginner
User Rating 3.7 (11 globes from 3 users)
Compatibility VB 5.0, VB 6.0, VB Script
Category String Manipulation
World Visual Basic
Archive File

API Declarations

Public Enum enPadString
 pdLeft
 pdRight
End Enum

Source Code

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published