Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFIF using Len Function

Guest
Sep 09, 2008 Sep 09, 2008
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.
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2008 Sep 09, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 09, 2008 Sep 09, 2008
LATEST
Why not just add a <br /> to any string that is less than 25 characters?

<cfset string = string & "<br />">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources