ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 6th, 2005, 10:33 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 23 m 47 sec
Reputation Power: 4
Adjusting text to title case

I think I'm overthinking this. I need to take a person's name or a sentence and convert it from the case it is to title case.

So, "the dog was smart" would become "The Dog Was Smart"

ColdFusion has ucase and lcase, neither will work on it's own to do what I want. I've thought about running a list loop on the statement with the delimiter being the space. As each word comes in, the first letter will be capitalized. The code is:

<cfloop index="curWord" list="#passedString#" delimiters=" ">
<cfset firstLetter = left(curWord,'1')>
<cfset wordLen = len(curWord)>
<cfset finishedWord = right(curWord,wordLen - 1)>
<cfset finalValue = finalValue & ucase(firstLetter) & lcase(finishedWord) & " ">
</cfloop>

This would work well for names, but I'm afraid it will drag on long sentences. Am I way overthinking this? Is there a better way to do it?

Reply With Quote
  #2  
Old May 6th, 2005, 11:31 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,661 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 14 h 23 m 22 sec
Reputation Power: 53
Always check cflib.org first. http://www.cflib.org/udf.cfm?ID=116
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old May 10th, 2005, 10:41 AM
fx910 fx910 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Australia
Posts: 31 fx910 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 16 m 59 sec
Reputation Power: 6
The UDF that Kiteless links to is very good, and your method is pretty fine, too. A small speeding-up would be:
Code:
<cfset Finished = "">
<cfloop list="My_Sentence" delimiters=" " index="C1">
<cfset Finished = Finished
                  & " "
                  & Ucase(Left(C1, 1))
                  & Iif(Len(C1 GT 1), DE(Right(C1, Len(C1) - 1), DE(""))>
</cfloop>
<cfset Finished = trim(Finished)>

Reply With Quote
  #4  
Old May 11th, 2005, 09:05 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 23 m 47 sec
Reputation Power: 4
Thanks, guys!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Adjusting text to title case


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway