Book a Demo

Author Topic: Using backslash character in CGT macros  (Read 4584 times)

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Using backslash character in CGT macros
« on: April 08, 2009, 07:00:01 pm »
Hi,

Ever needed to use a single backslash character '\' in code generation macros?
It took me hours and hours until I found out how this is possible, so I want to share this with all of you. Actually I wanted to replace the '\' in the %importRelativeFilePath% macro (another undocumented one BTW).

The 1st approach was (intuitively) as follows:

Code: [Select]
$path = %REPLACE(importRelativeFilePath,"\\","/")%
That didn't work :(, so I tried another variant:
Code: [Select]
$path = %REPLACE(importRelativeFilePath,"\","/")%
This didn't work either, and gave even worse results. So the reason apparantly is that the 1st variant "\\" really renders two backslash characters, while the 2nd variant just escapes the closing ".
Knowing that, you can use the following code to get a single \ character and use it in the REPLACE macro for example:

Code: [Select]
$bs=%LEFT("\\",1)%
$path = %REPLACE(importRelativeFilePath,$bs,"/")%

I hope this helps anyone else. May be Sparx should drop a note about the strange behavior of the \ character in literals in the 'Literals' section of the CGT macro documentation.

WBR
Günther



g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using backslash character in CGT macros
« Reply #1 on: April 09, 2009, 07:08:56 am »
Quote
%importRelativeFilePath% macro (another undocumented one BTW)

Sorry Sparxians, just didn't see it, its documented ...

Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/