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
Thinjon100
Apprentice


Joined: 12 Jul 2004
Posts: 190
Location: Canada

PostPosted: Sat Jan 29, 2005 2:37 pm   

Escaping Square Brackets
 
I've looked through all the documentation I thought could help with this, and ran quite a few Forum searches trying to see if anyone else had run into a similar problem...

I'm writing part of a script that will capture some selected text on the screen (using %selected), and save that for use in triggers later on. As I'm using it for triggers, I want to escape certain characters before I store the string, most notably the tilde ~, parenthesis (), asterisk *, and square brackets []. among a few other special chars... most of these have been easily accoutned for with a simple nested replace statement... i.e.
$replace(%selected,~,~~)
escapes the tilde with a double-tilde, so the pattern when put into a trigger later on, will not be disturbed. The problem is that I cannot, no matter what combination I've tried, seem to get square brackets to even appear, much less be escaped... and any special characters within the square brackets disappear as well... an example:
The selected text on the screen is...
~[()]~ Testing Testing ~[()]~
I saved this to a variable with an alias captext which reads:
#VAR testvar @escapechars(%selected)
and escapechars reads...
%replace(%replace(%replace(%replace(%replace(%1,~,~~),"(","~("),")","~)"),"[","~["),"]","~]")
The contents of test, however, are then
~~~~ Testing Testing ~~~~
the escaping of parenthesis and tildes works fine without the square brackets, and I've tried every combination of replace statements and bracket-controlstrings I could think of to try to get the brackets saved in the variable escaped...

I'm also looking to eventually distribute this, so avoiding System Preference changes would be nice, if possible.

Any help you can give would be appreciated.
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Mon Jan 31, 2005 2:57 am   
 
Try this:
Code:
#alias captext {#VAR testvar {%literal(%quote(%selected))}


* I edited the quote in. Missed the error because I don't expand []'s.


Last edited by Pega on Mon Jan 31, 2005 11:13 am; edited 2 times in total
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Jan 31, 2005 9:58 am   
 
You should also be able to use the %quote function to preform the needed tilde insertions rather then a mass of replaces.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Mon Jan 31, 2005 11:09 am   
 
Yep %quote works. %literal is meant for a command-line production of an alias.
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