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/

Reply via email to