TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Replacing contents of a string multiple times

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
abedour



Joined: 29 Oct 2010
Posts: 33

PostPosted: Fri Jul 06, 2012 4:58 am    Post subject: Replacing contents of a string multiple times Reply with quote

I'm working on a script that would replace certain words with different words, when you type "Say <whatever here>"

Basically, it's like creating an engine to give the impression that the person talking is drunk. For instance,

Code:
say "I'm not drunk officer!"
Would return: "I'm not drunk ociffer!"


And so on and so forth. HOWEVER, when I want simple things to be changed like "and" "whatever" so that whenever I typed:

Code:
say "And?!"
Would return "Whatever?!"


And I happened to type, instead, "You sandy bafoon!", it would return: You Swhatevery bafoon!"

Is there ANY way to fix this with regex, or something similar?

The code below:

Code:

#alias {say %0} {#send say @replacesay{%0}}
#function replacesay {
  #unvar a;
  #unvar b;
  #unvar ret;
  #unvar r12;
  #unvar r22;
  #unvar result;
  #if {&{repsay}} {
  #var ret %0;
  #format ret {%s%s%s} { } {$ret} { };
  #var a 1;
  #var b &repsay[];
  #while {$a <= $b} {
    #showme {@split{$repsay[$a]}\};
    #math a {$a +1}
  };
  #return $ret
 };
 #else { #return %0}
}

#function split {
  #var r12 %1;
  #var r22 %2;
  #format r12 {%s%s%s} { } {$r12} { };
  #format r22 {%s%s%s} { } {$r22} { };
  #replace ret $r12 $r22;
  #return
}


Replacements would be placed into var repsay like so: #var repsay[1] {Yes;no!} -- Yes being the old word, and no! being the word that it replaces it with.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Fri Jul 06, 2012 10:30 pm    Post subject: Reply with quote

Use the word boundary code, \b for that:

\band\b will match ' and ' but not 'bland'
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group