Well, another (easier?) way to handle it would be to think of your input
string as a <space> delimited list; you can then process each word easily.


<CFSET skipAllCapsWordsP = true>
<CFSET myString = "fourscore and seven years ago at IBM">
<CFSET mySkipList = "and,the,a,in,at">
<CFSET myFormattedString = myString>


<CFLOOP INDEX="loopCounter" FROM="1" TO="#listLen(myString,' ')#" STEP="1">
        <CFSET myWord = listGetAt(myString,loopCounter," ")>
        <CFSET skipThisWordP = false>
        
        <CFIF skipAllCapsWordsP>
                <!--- skip "all cap" words --->
                <CFIF Compare(ucase(myWord),myWord) IS 0>
                        <CFSET skipThisWordP = true>
                </CFIF>
        </CFIF>
        
        <!--- capitalize the first word, even if it's in the skip list --->
        <CFIF NOT skipThisWordP AND listFind(mySkipList,myWord) AND
loopCounter NEQ 1>
                <CFSET skipThisWordP = true>
        </CFIF>

        
        <CFIF NOT skipThisWordP>
                <CFSET myFormattedWord = ucase(left(myWord,1)) &
lcase(mid(myWord,2,len(myWord)))>
                <CFSET myFormattedString = listSetAt(myFormattedString,
loopCounter, myFormattedWord, " ")>
        </CFIF>
</CFLOOP>


<CFOUTPUT>#myFormattedString#</CFOUTPUT>         

-----Original Message-----
From: Richard Kuryk [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 27, 2001 10:37 AM
To: CF-Talk
Subject: RE: Title Case for proper names.......


Here is a title case custom tag that I wrote.  I realized that the regular
expressions in cold fusion just aren't all as powerful as in perl.  If
anyone has any suggestions on ways to optimize this even more please let me
know.

Thanks

Rich


<CFPARAM name="Attributes.original" default="">
<CFPARAM name="Attributes.searchlist" default="">
<CFPARAM name="Attributes.replacevaluelist" default="">
<CFSCRIPT>
        cur_pos = 2;
        new_string = Ucase(Left(Attributes.original,1));
        do {
                st = REFind("([[:space:]]+[[:alpha:]])",
Attributes.original, cur_pos, "TRUE" );
                if ( st.pos[1] GT 0 ) {
                        new_string = new_string &
LCASE(Mid(Attributes.original, cur_pos, (st.pos[1]-cur_pos)));
                        new_string = new_string &
UCASE(Mid(Attributes.original, st.pos[1], st.len[1]));
                } else {
                        new_string = new_string &
LCASE(Right(Attributes.original, (len(Attributes.original)-cur_pos)+1));
                }
                cur_pos = st.pos[1] + st.len[1];
         } while ( cur_pos is NOT 0 );
         if ( ListLen( Attributes.searchlist ) GT 0 ) {
                new_string = ReplaceList(new_string, Attributes.searchlist,
Attributes.replacevaluelist);
         }
         Caller.output=new_string;
</CFSCRIPT>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to