MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Replaceing a substring with some other substring
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Replaceing a substring with some other substring

 Post Reply Post Reply
Author
Message
mert View Drop Down
Member
Member


Joined: 16.Mar.2016
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote mert Quote  Post ReplyReply Direct Link To This Post Topic: Replaceing a substring with some other substring
    Posted: 03.Apr.2018 at 10:44
Dear All,

In my DSL development, I want to replace the "result" substring in a user-entered statement with the "result_"+$variable. Note here that $variable holds another user-entered data. 

I have tried the translator operator as below but it did not work. 

   to 
'%resultTranslator' newline '$result $result_$variable'
   endto 

and used the translator as follows:
:userStatement%resultTranslator;
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 537
Post Options Post Options   Thanks (1) Thanks(1)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 04.Apr.2018 at 09:08
If $variable is a MERL variable, then you'll need to use it outside string quotes - otherwise you're just asking to translate that part every time to the literal string '$variable'. For simple cases, where $variable contains just alphanumeric characters, you thus have:
to '%resultTranslator' newline '$result $result_' $variable endto
When that is evaluated with $variable='value', the translator is thus defined to translate 'result' into 'result_value'. 

If $variable can contain characters that are special to MERL translators (newline space \ / $ % - *) - then you should escape these when using it in the translator. A translator to translate escapable characters is of course pretty ugly, as the escapes need to be escaped, but here it is:
to '%escape
\' newline ' $\\\' newline '
\  $\\\ 
\\ $\\\\
\/ $\\\/
\$ $\\\$
\% $\\\%
\- $\\\-
\* $\\\*'
endto

to '%resultTranslator' newline '$result $result_' $variable%escape endto
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 10.16
Copyright ©2001-2013 Web Wiz Ltd.

This page was generated in 0.047 seconds.