Skip to main content
Inspiring
February 10, 2007
Question

Force UpperCase, with exclusions

  • February 10, 2007
  • 1 reply
  • 281 views
Greetings,
I am a low level CF programmer and have a problem to solve a bit above my skill level. Can anyone help add to this code to solve the problem.

I have the following CF code, that pulls from a db the news for a client's news page. The coding forces the news title to display the first letter of each word in UPPERCASE. BUT, there are a few words that I'd like to be excluded from this, and left as all upppercase (ex. USA..... not Usa). Here's the code I have now:

<cfoutput query="rsGetNews">
<cfset jon="rsGetNews.newstitle">
<cfscript> function ucwordss(jon) { jon = lcase(jon); wordsCapFirst = ""; for (i=1; i LTE ListLen(jon," "); i=i+1) { jonTemp = ListGetAt(jon,i," "); jonTemp = ucase(left(jonTemp,1)) & mid(jonTemp,2,len(jonTemp)-1); wordsCapFirst = ListAppend(wordsCapFirst,jonTemp," "); } return wordsCapFirst; } </cfscript>

#ucwordss(rsGetNews.newstitle)#

</cfoutput>

How do I rewrite this so that USA, CANADA, and ENGLAND are not given lowercase letters?

Many thanks,
Stephen
Tallahassee, FL
</a></li>
</cfoutput>
    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    February 10, 2007
    I have included punctuation, so that the place names in "We're in England; they're in Canada." can also be converted.