Solved

Change case of a string after a space

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function 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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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