How do you pad a string variable with characters on one side or the other?

Thanks!

Re: padding a string with characters by Agoston

Agoston
Fri Dec 03 03:44:39 CST 2004


I suppose you want to pad the strings to a fixed size. There's no such
function in vbscript, but you can write your own, .e.g

Function PadLeft(sStr, nWidth)
If Len(sStr) < nWidth Then
PadLeft = String(Len(sStr)-nWidth, " ") & sStr
End Function
End Function

"meg" <martorellg@hotmail.com> wrote in message
news:41affcfd$1@news.microsoft.com...
> How do you pad a string variable with characters on one side or the other?
>
> Thanks!
>
>



Re: padding a string with characters by meg

meg
Fri Dec 03 10:36:36 CST 2004

Thank you I'll try this!

"Agoston Bejo" <gusz1@freemail.hu> wrote in message news:O8L3q1R2EHA.3120@TK2MSFTNGP12.phx.gbl...

I suppose you want to pad the strings to a fixed size. There's no such
function in vbscript, but you can write your own, .e.g

Function PadLeft(sStr, nWidth)
If Len(sStr) < nWidth Then
PadLeft = String(Len(sStr)-nWidth, " ") & sStr
End Function
End Function

"meg" <martorellg@hotmail.com> wrote in message
news:41affcfd$1@news.microsoft.com...
> How do you pad a string variable with characters on one side or the other?
>
> Thanks!
>
>




Re: padding a string with characters by Don

Don
Fri Dec 03 15:41:36 CST 2004


"meg" <martorellg@hotmail.com> wrote in message
news:41affcfd$1@news.microsoft.com...
> How do you pad a string variable with characters on one side or the other?
>
> Thanks!
>
>

Function PadWithSpacesR(theString, TheCount)
Dim sTempInput, iCharCount,sPadding
sTempInput = Trim(theString)
iCharCount = Len(sTempInput)
sPadding = String(TheCount - iCharCount," ")
PadWithSpacesR =sTempInput & sPadding
End Function

Function PadWithSpacesL(theString, TheCount)
Dim sTempInput, iCharCount,sPadding
sTempInput = Trim(theString)
iCharCount = Len(sTempInput)
sPadding = String(TheCount - iCharCount," ")
PadWithSpacesL = sPadding & sTempInput
End Function



Re: padding a string with characters by meg

meg
Fri Dec 03 16:25:54 CST 2004

Thank you Don :)

"Don Grover" <dgrover@assoft.com.au> wrote in message news:#VOCgDY2EHA.1408@TK2MSFTNGP10.phx.gbl...

"meg" <martorellg@hotmail.com> wrote in message
news:41affcfd$1@news.microsoft.com...
> How do you pad a string variable with characters on one side or the other?
>
> Thanks!
>
>

Function PadWithSpacesR(theString, TheCount)
Dim sTempInput, iCharCount,sPadding
sTempInput = Trim(theString)
iCharCount = Len(sTempInput)
sPadding = String(TheCount - iCharCount," ")
PadWithSpacesR =sTempInput & sPadding
End Function

Function PadWithSpacesL(theString, TheCount)
Dim sTempInput, iCharCount,sPadding
sTempInput = Trim(theString)
iCharCount = Len(sTempInput)
sPadding = String(TheCount - iCharCount," ")
PadWithSpacesL = sPadding & sTempInput
End Function