House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  Regular Expressions (RegEx)

Capitalize first letter of all words

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
10/02/2008 01:20 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Adrian Lynch
10/02/2008 01:38 PM

If you don't mind a loop solution: http://cflib.org/index.cfm?event=page.udfbyid&udfid=889 Adrian 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
10/02/2008 01:40 PM

On Thu, Oct 2, 2008 at 18:15, Ian Skinner <HOF@ilsweb.com> 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>


<< Previous Thread Today's Threads Next Thread >>

Search regex

June 20, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
             1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30             

Designer, Developer and mobile workflow conference