Capitalize first letter of all words.

View: New views
3 Messages — Rating Filter:   Alert me  

Capitalize first letter of all words.

by Ian Skinner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The trick being that this has to work on a ColdFusion 4.5 server, so the
/u switch is apparently out!

I have reReplace(myString,'(^.| .)','-\1-','ALL') working so that it
captures the first character of all the words.  Now I need to find away
to convert the back reference to an upper case version of itself.

Anybody got any ideas?

TIA
IAN

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1175
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21

RE: Capitalize first letter of all words.

by Adrian Lynch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you don't mind a loop solution:

http://cflib.org/index.cfm?event=page.udfbyid&udfid=889

Adrian

-----Original Message-----
From: Ian Skinner [mailto:HOF@...]
Sent: 02 October 2008 18:15
To: regex
Subject: Capitalize first letter of all words.


The trick being that this has to work on a ColdFusion 4.5 server, so the
/u switch is apparently out!

I have reReplace(myString,'(^.| .)','-\1-','ALL') working so that it
captures the first character of all the words.  Now I need to find away
to convert the back reference to an upper case version of itself.

Anybody got any ideas?

TIA
IAN

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1176
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21

Re: Capitalize first letter of all words.

by Peter Boughton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 2, 2008 at 18:15, Ian Skinner <HOF@...> wrote:
> The trick being that this has to work on a ColdFusion 4.5 server, so the
> /u switch is apparently out!

Does it work if you put the slash the right way round? (it's \u not /u)

Can CF4.5 use Java objects? If so, you can use RegEx within Java.


> I have reReplace(myString,'(^.| .)','-\1-','ALL') working so that it
> captures the first character of all the words.

Hmmm, at the very least those "." should almost certainly be "\w".
Depending on what you're actually doing, simply "\b\w" might be better.
(But that doesn't help without being able to act on the results)


>  Now I need to find away
> to convert the back reference to an upper case version of itself.
>
> Anybody got any ideas?

Other than using Java, if possible, I can't think of a RegEx solution for this.

However, this is a crude non-RegEx solution that might be good enough for you:

<cfloop index="i" from="1" to="#ListLen(myString,' ')#">
        <cfset CurWord = ListGetAt( myString , i , ' ' )/>
        <cfset CapsWord = UCase(Left(CurWord,1)) & Right(CurWord,Len(CurWord)-1)/>
        <cfset myString = ListSetAt( myString , i , CapsWord , ' ' )/>
</cfloop>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1177
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21