[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2107
  • Last Modified:

ColdFusion: Proper Case Function?

Hi,
I was wondering if someone could point me to a solid UDF, UDT or CFC that takes a string of "words" and converts them into proper "title case".  This is where
-  the first letter of each word is uppercase
-  rest of each word is lower case
-  does not capitalize words that are prepositions, articles (you know - the small connector words)
-  Handles some common abbreviations?

You know what I mean (I hope).

Thanks in advance,
hefterr
0
hefterr
Asked:
hefterr
  • 3
  • 3
  • 2
1 Solution
 
_agx_Commented:
This is not really an answer, but .. :) with stuff like that I always check cflib.org first. CapFirstTitle might do some of what you need. I highly doubt it'll do everything (like exclude all "prepositions" and "abbreviations"), but maybe you can customize it.
0
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
0
 
hefterrAuthor Commented:
The CapFirstTitle is close to what I am looking for.  Just one more related question.  How does one test a string in CF to see if the alphabetic characters are all upper case?  It's related because I beleive this is why my boss wants to use this function.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
Gurpreet Singh RandhawaWeb DeveloperCommented:
like this:

<cfif str neq ucase(str)>
Incorrect
<cfelse>
Correct
</cfif>
0
 
_agx_Commented:
> <cfif str neq ucase(str)>

Not quite. NEQ is case *insensitive*

You can either use a regex or compare() the string to the upper case version (compare is case sensitive)

      <cfif compare( someString, ucase(someString)) eq 0>
            all upper case
      <cfelse>
            NOT all upper case
      </cfif>
0
 
hefterrAuthor Commented:
Thanks for your help.
0
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
but agx, NEQ will work, Can you explain me better why?
0
 
_agx_Commented:
Nope, it won't. NEQ doesn't care about case so it treats "apple" and "APPLE" the same.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now