Title: RE: [cfaussie] RE: Insert spaces in long words...?
****************************************************************
 
This e-mail is subject to the disclaimer contained at the bottom of this message.
 
*****************************************************************
:

...yea, that might do it....

;)

Thanks Ben, I'll give this a go :) And yeah, Taco, you're right - if someone's messing with the system, they deserve to see crappy results. Problem is, all the other users would see it too...

Cheers guys!
jb :)

_____________________________________________
From:  [EMAIL PROTECTED]@AUS   On Behalf Of Ben Bishop <[EMAIL PROTECTED]>
Sent: Friday, June 13, 2003 2:38 PM
To: CFAussie Mailing List

Taco Fleur wrote:

> Otherwise I guess you would need to loop over each word, by using the
> space as the delimiter, check the length of each word (len()) if
> greater than 50 break it up with (mid()) insert a break (<br
> />) and append it to a variable. Append the word even if its not
> greater than 50 so you get your original string back with words
> greater than 50 chars split up. Off course I think this would really
> use up some processing power.

Wot, something like this?

<cfscript>
function Wrap(string, linelength) {

      if(not len(string))
      string = "This function requires a string!";
      returnstring = "";
      string=replace(string,chr(10),chr(13)&chr(32),"all");
      delims=chr(32);
      linepos = 0;
      for(stringpos=1; stringpos lte listlen(string,delims);

stringpos=stringpos+1) {
word = listgetat(string,stringpos,delims);
hyphenpos = find(chr(45),word);
// Wrapping logic
if(len(word) gt linelength) { // Cut word after line length

            caseval = 1;
            breakpos = linelength;
            charcount = len(word)-linelength;
            linepos = 0;

          }
          else if(word contains chr(13)) { // Break found in this word

            caseval = 3;
            charcount = 0;
            linepos = 0;

          }
          else if(linepos eq 0) { // First word of line

            caseval = 0;
            charcount = incrementvalue(len(word));

          }
          else if(linepos+len(word) lt incrementvalue(linelength)) {

// Word fits on current line
caseval = 3;
charcount = incrementvalue(len(word));

          }
          else if(hyphenpos and (linepos+hyphenpos) lt

incrementvalue(linelength)) { // Wrap word at hyphen
caseval = 1;
breakpos = hyphenpos;
charcount = incrementvalue(len(word)-breakpos);
linepos = 0;

          }
          else {

            // Wrap word to new line
            caseval = 2;
            charcount = len(word);
            linepos = 0;

          }
          switch(caseval) {

            case 1: // Word is split at BreakPos by CR and appended
            returnword = chr(32)&insert(chr(13),word,breakpos);
            break;
            case 2: // Word is preceded by CR and appended
            returnword = chr(13)&word;
            break;
            case 3: // Word is appended with a leading space
            returnword = chr(32)&word;
            break;
            default: // Word is appended
            returnword = word;

          }
          returnstring = returnstring&returnword;
          linepos = linepos+charcount;

      }
      returnstring=replace(returnstring,chr(13),"<br

/>"&chr(13),"all")&"<br />";
}
</cfscript>


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/

:
 
*******************************************************************
The information transmitted in this message and attachments (if any)
is intended only for the person or entity to which it is addressed. 
The message may contain confidential and/or privileged material. 
Any review, retransmission, dissemination or other use of, or taking
of any action in reliance upon this information, by persons or entities
other than the intended recipient is prohibited. 
If you have received this in error, please contact the sender and delete this
e-mail and associated material from any computer.
The intended recipient of this e-mail may only use, reproduce, disclose or
distribute the information contained in this e-mail and any attached files,
with the permission of the sender.
This message has been scanned for viruses and cleared by MailMarshal.
********************************************************************
:
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/

Reply via email to