Solved

Change case of a string after a space

Posted on 2013-11-20
3
270 Views
Last Modified: 2013-11-20
I have 2 variables, FirstName and LastName. These are always returned in CAPS. Sometimes the Firstname has a space and then a middle inital. So, the firstname might be something like BOB R.
On cfoutput I want to convert that to Bob R. Can someone assist? Basically, if there is a space and then another letter in the string I want the letter after the space to be uppercase as well.
Thank you.
0
Comment
Question by:earwig75
  • 2
3 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 39663253
Something like this:

<cfset theName = "BOB MATHEW ROBERTSON">
<cfloop index="word" list="#theName#" delimiters=" ">
    #ucase(left(word,1))##lcase(right(word,len(word)-1))#
</cfloop>
0
 

Author Comment

by:earwig75
ID: 39663294
Receiving error: "The 2 parameter of the Right function, which is now 0, must be a positive integer."

Sometimes the name is just : BOB

Sometimes it is BOB S
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39663306
<cfset theName = "BOB MATHEW ROBERTSON">
<cfloop index="word" list="#theName#" delimiters=" ">
   <cfif len(word) gt 1>
       #ucase(left(word,1))##lcase(right(word,len(word)-1))#
    <cfelse>
        #ucase(word)#
    </cfif>
</cfloop>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now