Replacing words and phrases in commands

Posted by Vercalos on Wed 14 Sep 2011 11:21 PM — 7 posts, 26,645 views.

#0
Is there any way of taking a command, sending

A B C B B C B

and replacing every instance of B in the command with -B-?

I'm trying to make an alias to automatically insert ANSI into anything between "", rather than making a seperate alias for A "B", "B", A "B" C "B" and so on.
USA #1
Look at string.gsub()

Example used in the help file:

string.gsub ("nick eats fish", "fish", "chips") --> Nick eats chips


In your case:

string.gsub("A B C B B C B","B","-B-")
#2
So would that work for when I send commands?

And that means writing a script?
Australia Forum Administrator #3
You would write an alias - that matches something. Then inside the alias do "send to script" and do something like string.gsub to replace things. Then do a Send (results) to send the replaced text to the MUD.

You need to get the string.gsub right, eg. you may not want to replace letters inside other words, for example.
#4
Nick Gammon said:

You would write an alias - that matches something. Then inside the alias do "send to script" and do something like string.gsub to replace things. Then do a Send (results) to send the replaced text to the MUD.

You need to get the string.gsub right, eg. you may not want to replace letters inside other words, for example.

Well my main concern goal is to make commands go from

"A" B "C" to "[ansi(*,A)]" B "[ansi(*,C)]"

Without adding ansi tags to B, etc.
Australia Forum Administrator #5
Can you give a more concrete example? Are A B and C words? Consisting of A-Z? Or digits as well? Will they have spaces in them?
#6
like turn
"I said I wasn't going to go," the man replied in a very annoyed voice, "you kill yourself if you want but I'm staying here!"

into
"[ansi(*,I said I wasn't going to go,)]" the man replied in a very annoyed voice, "[ansi(*,you kill yourself if you want but I'm staying here!)]"

Basically, I'm trying to automatically color speech in a MUSH.
<EDIT>


Hello?