Skip to main content
May 3, 2006
Answered

how to pad a string

i am tryign to pad a strign with 38 blank spaces at the end. i tried the following:
<cfset filler="THisIsMyStringToPad">
<cfloop from="1" to="38" index="LoopCount">
<cfset filler= #variables.Filler# & " ">
#LoopCount#<br />
</cfloop>

but when i output #variables.Filler# to the screen, all i get is one space.

and i know it is going all the way through the loop because if i output loopcount on each iteration i get 1-38.

so what am i doing wrong? is there an easier way?
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer
    May 3, 2006
    ok nevermind - i figued this out with a google search. the answer is two fold:
    1) instead of using a loop - i can just say <cfset filler=#repeatString(" ",38)#>
    2) when i output it to the screen it is nto goign to show all the spaces because in HTML, it will only display one space in a row - i can get a better idea of whats going on by outputting filler wrapped in <pre> tags.

    1 reply

    Correct answer
    May 3, 2006
    ok nevermind - i figued this out with a google search. the answer is two fold:
    1) instead of using a loop - i can just say <cfset filler=#repeatString(" ",38)#>
    2) when i output it to the screen it is nto goign to show all the spaces because in HTML, it will only display one space in a row - i can get a better idea of whats going on by outputting filler wrapped in <pre> tags.
    Translate