Breaking long string in code

Moderator: leecollings

Post Reply
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Breaking long string in code

Post by tequila »

Hi guys,

I cannot figure out how to break a long code line in lua.
I have commandArray['SendEmail'] = 'subject#looong body sring#email'

All working just fine but not very comfortable to edit as it is all in one script line (not the output of the email, but the loa code itself).
How do I berak the code into more lines? Tried several thing but no luck.

I would like to achieve somethig like:

commandArray['SendEmail'] = 'subject#body part 1 /break
.. body part 2 /break
.. body part 3 #email'

to make it more convenient for editing.

Thanks
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: Breaking long string in code

Post by jmleglise »

I don't know bit You may use a variable :

body='some text'
body=body..'some text'
body=body..'some text'
Commandarray...= 'subject#'..body..email
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Re: Breaking long string in code

Post by tequila »

yeah, the point is that the body itself already contains quite a few variables so I am afraid this would be quite overkill.
tequila
Posts: 60
Joined: Tuesday 02 August 2016 17:08
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: Breaking long string in code

Post by tequila »

jmleglise wrote:I don't know bit You may use a variable :

body='some text'
body=body..'some text'
body=body..'some text'
Commandarray...= 'subject#'..body..email
So in the end this really seems to be the best option. I have not discovered a better way.

Thanks a lot, mate.
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Breaking long string in code

Post by jvdz »

Think you can also shorten it to:

Code: Select all

body = "line1" ..
"line2" ..
"line3" ..
"line4"
print(body)
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest