Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
jed
Adept


Joined: 18 Dec 2005
Posts: 246

PostPosted: 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
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: 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!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Jun 11, 2007 5:26 pm   
 
You're right. I forgot I was doing CMUD for this one. :)
_________________
Asati di tempari!
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: 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."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net