SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: Bamsen on May 10, 2017, 06:40:46 am

Title: How to define a multi line string variable?
Post by: Bamsen on May 10, 2017, 06:40:46 am
Hi, I would like to do something like this:

_str test = '
This is the first line
This is a new line
This is the last line of the variable test
';

Is there a way to specify that a variable assignment spans multiple lines in the source file?

---
Morten A. Steien
Title: Re: How to define a multi line string variable?
Post by: Clark on May 12, 2017, 11:39:36 pm
You can use string concatenation with a :+ at the end of the line.

Use "\n" to specify a new line character
Title: Re: How to define a multi line string variable?
Post by: Bamsen on May 13, 2017, 04:30:56 pm
A slight misunderstanding, i suspect. :)
The whole point is for the variable to span several lines in the source file.
The variable I need will be huge and having it on one line with \n is not practical.
Title: Re: How to define a multi line string variable?
Post by: Clark on May 13, 2017, 05:14:15 pm
_str text="line 1\n":+
    "Another line\n":+
    "More\n";

Hope this makes more sense
Title: Re: How to define a multi line string variable?
Post by: Bamsen on May 13, 2017, 08:57:52 pm
It will have to do.
Thank you for your help.  :)
Title: Re: How to define a multi line string variable?
Post by: LBCEi on May 13, 2017, 09:10:15 pm
Maybe another example will clarify what Clark is trying to tell you about the :+ string concatenation.

_str text="Line 1 that is really long and will not fit on my screen because it is really, really, really, really, ":+
    "really, really, really, really, really, really, a long line of text.\n":+
    "Line 2.\n":+
    "Another line\n":+
    "More\n";

Note that this is all one variable and that the 'Line 1' part of it is defined on two lines in the source but is really one 'line' in that it doesn't have a newline (\n) until the logical end of it.  So, 5 lines in the variable definition but only 4 lines of output if you choose to display this variable somewhere.
Title: Re: How to define a multi line string variable?
Post by: Bamsen on May 13, 2017, 09:20:11 pm
Yes. I understand.
What I was hoping for was some way of doing this without adding text in front (") and in the end (\n":+) of every source line.
I will just create a quick macro to reformat the lines accordingly.
Title: Re: How to define a multi line string variable?
Post by: Clark on May 13, 2017, 11:37:53 pm
I typically record a quick macro to format the lines the way I need them.

Slick-c doesn't have a here-doc syntax yet. Probably would be easy to add.