|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
Capitalize first letter of all words
The trick being that this has to work on a ColdFusion 4.5 server, so theIan Skinner 10/02/08 01:20 P If you don't mind a loop solution:Adrian Lynch 10/02/08 01:38 P On Thu, Oct 2, 2008 at 18:15, Ian Skinner <HOF@ilsweb.com> wrote:Peter Boughton 10/02/08 01:40 P 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 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 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>
|
June 20, 2013
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||