just off the top of my head:

function spaceFiller(cell, fill, align) {
     var space = RepeatString(' ', fill - Len(Cell));
     return iif(align eq 'R', de(space & cell), de(cell & space));
}

You may need to deal with the scenario of cell having more characters
than the value of fill. Also, if you're spitting out html and want the
space to be visible, use white-space:pre in the css of the containing
element.

On 22 August 2011 17:19, Josh Cesana <joshuaces...@yahoo.com> wrote:
>
> I'm attemping to create a function that adds spaces either in front of or 
> behind a string. For example, I want this "test" string to have 6 spaces 
> after it, plus the 4 characters in "test" for a total of 10 characters. I 
> have an "align" variable for both left and right alignment for the spaces. So 
> far, the only result I get is 'test ' instead of 'test      '
>
> <CFSCRIPT>
>
>    function spaceFiller(cell, fill, align) {
>        var newcell = "";
>        if (len(cell) EQ 0) {
>            cell = " ";
>        }
>        newcell = cell;
>        for (i=1; i EQ len(fill - (len(cell))); i=i+1) {
>            if (align EQ "R") {
>                newcell = " " & newcell;
>            } else { newcell = newcell & " ";
>            }
>
>        }
>        return (newcell);
>    }
> </CFSCRIPT>
>
> <cfoutput>
> 10 characters - align left: '#spaceFiller("test","10","L")#'
> </cfoutput>
>
> The result I get is 'test ' and what I want is 'test      '
>
> Any help would be much appreciated - thanks in advance.
> -J
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:346929
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to