Add linefeed to begin of string

Hello,
I have a display connected to a serial line. That display clears its screen if it receives a linefeed. (I wrote the code myself, it is a ATTiny2313 with a 2x16 LCD screen attached and a RS232 driver/reciever chip and 4 buttons)
I want to display some information on it but I need to clear the screen in advance.
So my question is: how to put a \n in front of a string? (msg.payload)
I searched and found something with JSONata but could not make it to work.

template node to add a prefix and then \n?

So it would be (in the template node):
\n{{msg.payload}}

May work.

1 Like

Should do.

Alternatively, a function node...

msg.payload = '\n' + msg.payload;
return msg;

I'm certain a JSONata version is possible too.

Edit - thoughts and musings....
I know JSONata is an order of magnitude times slower than the function node (I've posted about this before so I mostly avoid JSONata - but in this simple example, the difference will be negligible) however, I've never done a speed test between a function node and template node.

My thoughts are the mustache will be comparable to JSONata ? :thinking:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.