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
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 18, 2001 8:24 am   

Patterns and %replace()
 
I can't seem to wrap myself around this problem, but is it possible to find a pattern in a given string and then replace that pattern with something else?

I'm specificly looking to replace any instance of ordinal numbers with "" so that:

1st ork|2nd ork|1st ork-ra

will become:

ork|ork|ork-ra

There are only 4 ordinal tags (st, nd, rd, and th), so replacing them is no problem but there can be up to 50 NPCs of a given type and I'd rather not have 14 different %replace() functions.

li'l shmoe of Dragon's Gate MUD
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sun Nov 18, 2001 9:04 am   
 
Sadly one can't use wildcards in functions. This clunky function might serve:


#FUNCTION strip_ords {%right(%1, %if(%pos("1st ", %1), %eval(%pos("1st ", %1)+3), %if(%pos("2nd ", %1), %eval(%pos("2nd ", %1)+3), %if(%pos("3rd ", %1), %eval(%pos("3rd ", %1)+3), %if(%pos("th ", %1), %eval(%pos("th ", %1)+2), 1)))))}

As an exercise, I've left it to you to double check if I have enough parentheses.

If the only space in the item separates its ordinal position from its name, you could use:


#FUNCTION strip_ords {%right(%1, %pos(" ", %1))}


Troubadour
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 18, 2001 9:19 am   
 
quote:

#FUNCTION strip_ords {%right(%1, %pos(" ", %1))}



heh, I knew it was simple enough It's amazing what one forgets at 12 midnight...

Thanks, Troubadour

li'l shmoe of Dragon's Gate MUD
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