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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Eyeless
Wanderer


Joined: 02 Dec 2001
Posts: 80
Location: Canada

PostPosted: Thu Jan 29, 2004 5:20 am   

Stripping unwanted words, punctuation
 
#var loot %replace( "%1", ",", "|")

works great for commas, but how do I build it if I want to remove all punctuation and other certain words... for example: , ! . AND and.

also if I just want the right most word in each string item, is this possible as well?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jan 29, 2004 6:37 pm   
 
You can repeat the %replace as often as desired, changing any characters you don't want into characters which you do want. Among the things you can change to is a null string.
#VAR loot {%replace( "%1", ",", "|")}
#VAR loot {%replace({@loot}, "!", "")}
#VAR loot {%replace({@loot}, " and ", " ")}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jan 29, 2004 11:08 pm   
 
Also you might want to use %subchar. For example:
#VAR loot {%subchar("%1", "!.?:()[]<>", "")

This method is character based so it doesn't work for a phrase/word like "and", but can neatly eliminate all punctuation.
Reply with quote
Valint
Wanderer


Joined: 12 Nov 2003
Posts: 70
Location: USA

PostPosted: Fri Jan 30, 2004 2:01 am   
 
> also if I just want the right most word in each string item, is this possible as well?

One way to do so would be this, though there are likely more elegant ways out there:
#LOOP %numitems( @loot) {#VAR loot %replaceitem( %word( %item( @loot, %i), %numwords( %item( @loot, %i))), %i, @loot)}
Reply with quote
Eyeless
Wanderer


Joined: 02 Dec 2001
Posts: 80
Location: Canada

PostPosted: Fri Jan 30, 2004 3:24 am   
 
Thank you.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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