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

Replace curly braces in a string

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Fri Sep 13, 2013 10:16 am    Post subject: Replace curly braces in a string Reply with quote

I have a string that I would like to strip curly braces from (it is causing problems in the mapper because I have room names including curly braces)

Code:

#VAR {test} {\x7b something \x7d}

#OK. VARIABLE {test} HAS BEEN SET TO {\x7b something \x7d}.

#ECHO {$test}

{ something }

#REPLACE {test} {\x7b} {(}

#REPLACE: {\x7b} NOT FOUND IN {\x7b something \x7d}.

#LINE SUBSTITUTE ESCAPES #REPLACE {test} {\x7b} {(}

#Unmatched braces error!
#REPLACE: {{} {(}} NOT FOUND IN {\x7b something \x7d}.



Looks like the hex code escapes need to be applied at a different point in the replace code, or else a "raw" flag is needed.

Version 2.00.9
Back to top
View user's profile Send private message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Tue Sep 17, 2013 5:47 am    Post subject: Reply with quote

I have a work-around function that should replace all { with ( and } with ) within a string:



Code:

#FUNCTION {fStripBraces}
{

  #VAR {_fSB} {%1};
  #VAR {result} {};

  #IF {"${_fSB}" == ""}
  {
    #RETURN;
  };

  #WHILE {"$result" == ""}
  {
    #REGEXP {${_fSB}} {{(.*)\\x7B(.*)}}
    {
      #VAR {_fSB} {&2(&3};
    }
    {
      #REGEXP {${_fSB}} {{(.*)\\x7D(.*)}}
      {
        #VAR {_fSB} {&2)&3};
      }
      {
        #VAR {result} {${_fSB}};
      };
    };
  };
  #UNVAR {_fSB};
};


Code:

#VAR {test} {\x7B something \x7D}

#OK. VARIABLE {test} HAS BEEN SET TO {\x7B something \x7D}.

#ECHO {@fStripBraces{$test}}

( something )
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Sep 17, 2013 7:04 pm    Post subject: Reply with quote

I thought I replied to this, I must have closed to window without clicking submit last weekend.

Have you tried:

#REPLACE {test} {\\x7b} {(}

#replace substitutes escape codes so if you replace \b it'll replace a backspace rather than the literal "\b" string. Subsequently to replace the literal "\x7b" string you need to use \\x7b.
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 -> Bug Reports 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