Reputation: 1124
I have to write a text file using ColdFusion. In that text file I need 'n' number of white spaces between strings.
For example:
'This<44 spaces>is<60 spaces>a<120 spaces>sampleText.'
So for this I'm using the ljustify()
function in the places of white spaces, like
'This'&#ljustify(" ",44)#&'is'&#ljustify(" ",60)#&'a'&#ljustify(" ",120)#&'sampleText.'
I'm thinking that this will not be a coding standard. So, is there any other way to do this?
Upvotes: 2
Views: 578
Reputation: 1271
It looks like what you want is RepeatString()
.
Creates a string that contains a specified number of repetitions of the specified string
Takes two parameters:
"This" & RepeatString(" ",44) & "is" & RepeatString(" ",60) & "a" & RepeatString(" ",120) & "sampleText."
Of course, you don't need to use a space. You can use RepeatString
to repeat just about anything.
LJustify() is for "padding" a string with characters out to a set number of spaces.
Example:
[#LJustify("These",10)#]<br>
[#LJustify("are",10)#]<br>
[#LJustify("variable",10)#]<br>
[#LJustify("size",10)#]
would give you output like
[These ]
[are ]
[variable ]
[size ]
This is especially useful for creating fixed-length strings.
Upvotes: 4