Solved

Change case of a string after a space

Posted on 2013-11-20
3
269 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

21 Experts available now in Live!

Get 1:1 Help Now