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
Shezmu
Wanderer


Joined: 23 Apr 2010
Posts: 53

PostPosted: Fri Apr 23, 2010 10:25 pm   

Counting occurences in string
 
Okay, some of the more advanced CMud users will laugh at me for this one. I'm trying to count the number of occurences of the word "and" in the following string:

You join Steve and Mary and Mark and Frank and John in a threnody ritual.

What I want to build is a counter that shows me how many people are already in the ritual (to which I will increment when additional people join in until we reach enough people to complete the ritual.)

Like I said, this should be an easy one to solve, but I'm wracking my brain trying to find it. Suggestions?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Fri Apr 23, 2010 11:17 pm   
 
%eval(%numwords("<string>"," and ")-1) should give you the number of times 'and' occurs in the string, or 0 if it doesn't appear.

#SAY %eval(%numwords("You join Steve and Mary and Mark and Frank and John in a threnody ritual."," and ")-1)
returns 4.

Be sure to have spaces around the 'and' or the count will include other words which contain 'and', like someone named Moander, for instance.
Reply with quote
Shezmu
Wanderer


Joined: 23 Apr 2010
Posts: 53

PostPosted: Sat Apr 24, 2010 2:36 am   
 
Worked perfectly, Drax. Thanks for the help. I knew someone could answer this one easily. I'm still learning the ropes with CMud. Just switched over after Portal went under. I promise, I'll be back with more questions ;)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Apr 24, 2010 1:26 pm   
 
You don't actually need %eval there. Just use parentheses:
(%numwords("You join Steve and Mary and Mark and Frank and John in a threnody ritual."," and ")-1)
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