if(LEN(Words[j]) LT 4 ){
   if(ListFind(ArrayToList(excludeWords,","),Words[j])){
    doCap = false;

I wonder if it would be faster to do short-cut

 if(LEN(Words[j]) LT 4 and
ListFind(ArrayToList(excludeWords,","),Words[j]) )
{

}


Joe
-----Original Message-----
From: Douglas Brown [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 17, 2002 4:48 PM
To: CF-Talk
Subject: Re: capitalize first letter


Here is the capFirstTitle UDF. Just copy and paste it.

<CFSCRIPT>

/**
 * Returns a string with words capitalized for a title.
 * Modified by Ray Camden to include var statements.
 *
 * @param initText   String to be modified.
 * @return Returns a string.
 * @author Ed Hodder ([EMAIL PROTECTED])
 * @version 2, July 27, 2001
 */
function capFirstTitle(initText){

 var Words = "";
 var j = 1; var m = 1;
 var doCap = "";
 var thisWord = "";
 var excludeWords = ArrayNew(1);
 var outputString = "";

 initText = LCASE(initText);

 //Words to never capitalize
 excludeWords[1] = "an";
 excludeWords[2] = "the";
 excludeWords[3] = "at";
 excludeWords[4] = "by";
 excludeWords[5] = "for";
 excludeWords[6] = "of";
 excludeWords[7] = "in";
 excludeWords[8] = "up";
 excludeWords[9] = "on";
 excludeWords[10] = "to";
 excludeWords[11] = "and";
 excludeWords[12] = "as";
 excludeWords[13] = "but";
 excludeWords[14] = "if";
 excludeWords[15] = "or";
 excludeWords[16] = "nor";
 excludeWords[17] = "a";

 //Make each word in text an array variable

 Words = ListToArray(initText, " ");

 //Check words against exclude list
 for(j=1; j LTE (ArrayLen(Words)); j = j+1){
  doCap = true;

  //Word must be less that four characters to be in the list of excluded
words
  if(LEN(Words[j]) LT 4 ){
   if(ListFind(ArrayToList(excludeWords,","),Words[j])){
    doCap = false;
   }
  }

  //Capitalize hyphenated words
  if(ListLen(Words[j],"-") GT 1){
   for(m=2; m LTE ListLen(Words[j], "-"); m=m+1){
    thisWord = ListGetAt(Words[j], m, "-");
    thisWord = UCase(Mid(thisWord,1, 1)) & Mid(thisWord,2, LEN(thisWord)-1);
    Words[j] = ListSetAt(Words[j], m, thisWord, "-");
   }
  }

  //Automatically capitalize first and last words
  if(j eq 1 or j eq ArrayLen(Words)){
   doCap = true;
  }

  //Capitalize qualifying words
  if(doCap){
   Words[j] = UCase(Mid(Words[j],1, 1)) & Mid(Words[j],2, LEN(Words[j])-1);
  }
 }

 outputString = ArrayToList(Words, " ");

 return outputString;

}
</CFSCRIPT>





Douglas Brown
Email: [EMAIL PROTECTED]
----- Original Message -----
From: "Wurst, Keith D." <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 12:31 PM
Subject: capitalize first letter


> Hi everyone. I would like to capitalize the first letter of variable every
> time it is displayed. What is the easiest way to do this? Thanks very
much.
>

______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to