abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Fri Jul 06, 2012 4:58 am Post subject: Replacing contents of a string multiple times |
|
|
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. |
|