Author Topic: How to define a multi line string variable?  (Read 456 times)

Bamsen

  • Community Member
  • Posts: 41
  • Hero Points: 1
How to define a multi line string variable?
« 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

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3726
  • Hero Points: 243
Re: How to define a multi line string variable?
« Reply #1 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

Bamsen

  • Community Member
  • Posts: 41
  • Hero Points: 1
Re: How to define a multi line string variable?
« Reply #2 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.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3726
  • Hero Points: 243
Re: How to define a multi line string variable?
« Reply #3 on: May 13, 2017, 05:14:15 pm »
_str text="line 1\n":+
    "Another line\n":+
    "More\n";

Hope this makes more sense

Bamsen

  • Community Member
  • Posts: 41
  • Hero Points: 1
Re: How to define a multi line string variable?
« Reply #4 on: May 13, 2017, 08:57:52 pm »
It will have to do.
Thank you for your help.  :)

LBCEi

  • Senior Community Member
  • Posts: 157
  • Hero Points: 8
Re: How to define a multi line string variable?
« Reply #5 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.

Bamsen

  • Community Member
  • Posts: 41
  • Hero Points: 1
Re: How to define a multi line string variable?
« Reply #6 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.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3726
  • Hero Points: 243
Re: How to define a multi line string variable?
« Reply #7 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.