From: "Nathan Stanford" <[EMAIL PROTECTED]>

> 
> How can I Limit the output of words to 300 chars but don't cut off a word in
> the middle?
> 

In psuedo code --

target
define word
ListInsertAt 300th word some_unused_char_as_delimiter
goal = ListFirst(target)

in CF ( not guaranteed)
this is verbose and explicit, there should be a regex
that can do the same in one step (Rick Osborne??)

<!--- define: word
n chars ending in chr(32)
---->
<cfset spc=chr(32)>
<cfset lf=chr(10)>
<cfset cr=chr(13)>
<cfset lfcr=lf & cr>
<cfset rareChar=chr(135)>
<cfset thisFile="c:\foo\some_tract.txt"
<cffile
action = "read"
file=#thisFile#
variable=txt>
<cfset sanityCheck=FindOneOf(#spc#,txt)>
<cfset yesLF=FindOneOf(#lf#,txt)>
<cfset yesCR=FindOneOf(#cr#,txt)>
<cfif(sanityCheck)>
<cfset isIt_unix_or_dos_or_charStream=yesLF + yesCR>
<cfswitch expression="#isIt_unix_or_dos#">
<cfcase value=0> <!--- it's char stream ---->
<!--- do nothing --->
</cfcase>
<cfcase value=1> <!--- must be unix ---->
<cfset txt=ReplaceNoCase(txt,#lf#,#spc#,"ALL")>
</cfcase>
<cfcase value=2><!--- it's dos ---->
<cfset txt=ReplaceNocase(txt,#lfcr#,#spc#,"ALL")>
</cfcase>
</cfswitch>
<!--- now we have a stream of char representable as one long line --->
<!--- if the txt is properly punctuated,
(cf. differences tween English English and American English)
then txt is finished being prepped.
Might add in recursive code to replace instances where chr32
appears more than once in any given char sequence. Probably
should do this as some do two chr32 after periods and some
do one chr32. Code is trivial and left as exercise  :) 
-----> 
<cfset txt=ListSetAt(txt,300,#rareChar#,#spc#)>
<cfset goal=ListFirst(txt,#rareChar#)>
<cfelse>
<cfoutput>redefine word<br><cfabort></cfoutput>
</cfif>

rareChar selection should be informed by awareness of
language used in txt and by general knowledge of context
I.E. chr(135) will be likely in highly footnoted tracts
from academic types (especially history majors  :)  ).

Pan - the one and only Baroque programmer

  

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to