 |
jed Adept
Joined: 18 Dec 2005 Posts: 246
|
Posted: Mon Jun 11, 2007 3:50 pm
function similar to %proper |
Is there a function similar to proper that capitalizes the first letter of each word? I typically use notation like this when displaying names of things. i.e. the dragon tooth inn would be The Dragon Tooth Inn ?
If not, any chance it could be added as a function in a future version? Thanks for looking |
|
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Jun 11, 2007 4:35 pm |
There's no specific function, but you could use %proper on each word individually like
#VAR NewString ""
#LOOP 1 %numwords(@String) {NewString=%concat(@NewString," ",%proper(%word(@String,%i)))}
or you could try using a %subregex
#VAR NewString %subregex(@String, " [a-z]"," %upper(%1)");
The code is untested but should give you a general idea. The subregex searches for any letter with a space before it and capitalizes it. |
|
_________________ Asati di tempari! |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jun 11, 2007 4:42 pm |
The subregex idea is a good one, but you need to have the %upper function outside quotes and use %pat instead of %nn. The range needs to be captured, too. In the couple of minutes of experimentation I did, I couldn't get it to replace all the characters correctly, either - it'd always replace all the matches with the last one, giving you "the Iragon Iooth Inn". That regex also won't capture the beginning of the string - it'd be better to use \b. But you get the idea.
|
|
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Jun 11, 2007 5:26 pm |
You're right. I forgot I was doing CMUD for this one. :)
|
|
_________________ Asati di tempari! |
|
|
 |
Dharkael Enchanter

Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Tue Jun 12, 2007 10:09 am |
#var NewString %subregex(%lower(@String),"\b(\w)(\w*?)\b","%upper(%pat(1))%pat(2)")
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
 |
|
|
|