# Add linefeed to begin of string

**URL:** <https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288>\
**Category:** General\
**Created:** [7 August 2020 21:17 UTC](https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288 "2020-08-07T21:17:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![warnert](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/warnert/32/108132_2.png) [@warnert](https://discourse.nodered.org/u/warnert)\
**Post date:** [7 August 2020 21:17 UTC](https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288/1 "2020-08-07T21:17:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 August 2020 21:26 UTC](https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288/2 "2020-08-07T21:26:16Z")

</div>

`template` node to add a _prefix_ and then `\n`?

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

May work.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 August 2020 21:48 UTC](https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288/3 "2020-08-07T21:48:45Z")

</div>

Should do.

Alternatively, a function node...

```auto
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 ? 🤔

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 October 2020 21:48 UTC](https://discourse.nodered.org/t/add-linefeed-to-begin-of-string/31288/4 "2020-10-06T21:48:48Z")

</div>

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