-
I'm trying to build a dynamic string of zeros...
ie. "0000000". I want to be able to supply the number of
characters I need and then have the string generate.
If I need 4 I would call a function and return "0000", if I need 10 I would call the function and return "0000000000".
Is there a simple function similar to SPACE() function that allows you to supply the character you want repeated?
I've got a couple of methods (shown below) but I'm looking for the fastest code.
Code:
'Method 1: Use Space and Replace Functions
Dim strTemp As String
'I'm hard coding in a 6 for example purposes
'Normally I'd pass the value in to the function
strTemp = Space(6)
strTemp = Replace(strTemp, " ", "0")
'Method 2: Use for loop and append the string
Dim strTemp As String
Dim intCnt As Integer
strTemp = ""
For intCnt = 1 To 6
strTemp = strTemp & "0"
Next
Any insight anyone can provide will be appreciated.
-
String(6, "0") 'returns "000000"
-
Thanks. I knew it had to be something simple like that.