Skip to main content
September 9, 2008
Question

CFIF using Len Function

  • September 9, 2008
  • 2 replies
  • 1726 views
I have a page that display's products and it has descriptions in it that are pulled from a database however the problem is that we want to make them uniform and have the description fill 2 lines so my question is if I have a variable string that is 10 characters long then the way I was thinking is to add nbsp's to the end of the variable to make it = the string len of 24 plus 1 space make the line wrap to the next line. so I would have something like the code attached, does anyone else have a better way of doing it please let me know.
    This topic has been closed for replies.

    2 replies

    Miguel-F
    Inspiring
    September 10, 2008
    Why not just add a <br /> to any string that is less than 25 characters?

    <cfset string = string & "<br />">
    Inspiring
    September 10, 2008
    cf has a nice repeatstring() function:

    <cfoutput>
    <cfif len(trim(string)) lt 25>
    #repeatstring(' ', 25-len(trim(string))) & string#
    <cfelseif len(trim(string)) gt 25>
    #left(string, 22)#...
    <cfelse>
    #string#
    </cfif>
    </cfoutput>

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/