[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Replacing words and phrases in commands

Replacing words and phrases in commands

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Vercalos   (23 posts)  [Biography] bio
Date Wed 14 Sep 2011 11:21 PM (UTC)
Message
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.
[Go to top] top

Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Reply #1 on Wed 14 Sep 2011 11:47 PM (UTC)
Message
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-")
[Go to top] top

Posted by Vercalos   (23 posts)  [Biography] bio
Date Reply #2 on Thu 15 Sep 2011 12:40 AM (UTC)
Message
So would that work for when I send commands?

And that means writing a script?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 15 Sep 2011 09:28 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Vercalos   (23 posts)  [Biography] bio
Date Reply #4 on Fri 16 Sep 2011 04:46 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Fri 16 Sep 2011 06:00 AM (UTC)
Message
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?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Vercalos   (23 posts)  [Biography] bio
Date Reply #6 on Fri 16 Sep 2011 06:28 AM (UTC)

Amended on Sat 03 Dec 2011 04:02 AM (UTC) by Vercalos

Message
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?
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,051 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]