(keitai-l) Re: wrap text (for cold fusion)

From: <list_at_objekt>
Date: 09/26/01
Message-ID: <026f01c14659$a5dd6c30$0500a8c0@avex>
Hi everyone...

I found a solution to wrap text in cold fusion at a specified number of
characters.
Should I break at 20 characters for english text?

Here is the code if anyone is interested.  It is from a example email
application that came with cold fusion to wrap text on emails.  It inserted
a Chr(10), but i substituted it for a <br>.



test.cfm

<cfset newbody = "hello this is a bit of text done by, cold fusion blah blah
blah i am a sentance here we go.">
<CF_Wrap VARIABLE="NewBody" WIDTH="20">
<cfoutput>#newbody#</cfoutput>

wrap.cfm

<CFSETTING ENABLECFOUTPUTONLY="YES">


<!--- Initialize variables --->

<CFPARAM NAME="Attributes.BreakChars" DEFAULT=" -">
<CFSET BreakChars = Attributes.BreakChars>

<CFPARAM NAME="Attributes.Width" DEFAULT="80">
<CFSET Width = Attributes.Width>

<CFSET Newline = "<br>">

<CFSET Wrapped = "">

<CFSET Remaining =  evaluate("Caller." & Attributes.Variable)>



<!--- Loop until there are fewer than #WIDTH# characters left --->

<CFLOOP CONDITION="Len(Remaining) GT Width">

 <CFSET CurrentLine = Left(Remaining, Width)>
 <CFSET Remaining = Right(Remaining, Len(Remaining) - Width)>


 <CFIF Find(Newline, CurrentLine) NEQ 0>
  <CFSET Pos = Find(Newline, CurrentLine)>
  <CFSET Wrapped = Wrapped & Left(CurrentLine, Pos)>
  <CFIF Pos NEQ Len(CurrentLine)>
   <CFSET Remaining = Right(CurrentLine, Len(CurrentLine) - Pos) &
Remaining>
  </CFIF>

 <CFELSEIF FindOneOf(BreakChars, CurrentLine) NEQ 0>
  <CFSET CurrentLine = Reverse(CurrentLine)>
  <CFSET Pos = FindOneOf(BreakChars, CurrentLine)>
  <CFSET CurrentLine = Reverse(CurrentLine)>
  <CFSET Pos = Len(CurrentLine) - Pos + 1>

  <CFSET Wrapped = Wrapped & Left(CurrentLine, Pos) & Newline>
  <CFIF Pos NEQ Len(CurrentLine)>
   <CFSET Remaining = Right(CurrentLine, Len(CurrentLine) - Pos) &
Remaining>
  </CFIF>

 <CFELSE>
  <CFSET Wrapped = Wrapped & CurrentLine & Newline>

 </CFIF>

</CFLOOP>

<CFSET Wrapped = Wrapped & Remaining>

<CFSET "Caller.#Attributes.Variable#" = Wrapped>

<CFSETTING ENABLECFOUTPUTONLY="NO">





[ Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ ]
Received on Wed Sep 26 09:53:21 2001