That would be difficult as the function is splitting the phrase into words
using space as a delimiter. What you want to do is use brackets as a
delimiter too, but you don't want the brackets turned into spaces when the
words are reassembled back into a phrase.


If you are using CFMX, you could use this function instead. I just cobbled
this together and it's a bit ugly but seems to work.

<cfset myPhrase = "the quick brown (fox) jumps over (the) lazy dog the lazy
dog.">
<cfoutput>#headingCaps(myPhrase)#</cfoutput>
<cfscript>
function headingCaps(str) {
  var result = "";
  result = reReplace(str, "\b(\w)", "\U\1", "all");
  result = reReplace(result, "\b(The|A|An)\b", "\L\1", "all");
  result = reReplace(result, "(^|\()(\w)", "\1\U\2", "all");
  return result;
}
</cfscript>


  _____  

From: Mark Henderson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 6 October 2004 11:27 a.m.
To: CF-Talk
Subject: Capitalising first letter after an open bracket

've been using CapFirstTitle from cflib for some time now and it works
great. On this occasion however I need to make a modification and have it
also capitalising the first letter after an open bracket, which currently it
does not do...Here's the script
--------------------
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";
etc etc

//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;

}
------------------

It will even capitalise the first letter of hyphenated words. Is there any
way to add something to get it to cap the first letter AFTER an open
bracket, as currently it makes these all lowercase? I've done some regex
research and haven't managed to get anything working yet.

TIA
MarkH
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to