# Trying to split a status text on line break

**URL:** <https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168>\
**Category:** Dashboard\
**Created:** [24 November 2022 10:39 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168 "2022-11-24T10:39:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [24 November 2022 10:39 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/1 "2022-11-24T10:39:31Z")

</div>

I have a payload.status string with I believe line breaks. If I try to send the string as it is to my dashboard text node though, I have no line break. So I thought I try to split the string at the line break, then after each part I add a   
 and send it to the text node.  
Not sure this is the right approach though

Here is a screen grab of the debug, as when I try and copy paste the line break symbol it doesnt work.  
The screen grab has my attempt of splitting and on the right side status: "14/12 Thalia... is the string I need to split  
(this is a calendar retrieved from google calendar via Homeseer)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d5e1fbf5d7b14870eaa70cb4d0e2c314eff9ef6.png)

---

<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:** [24 November 2022 10:59 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/2 "2022-11-24T10:59:08Z")

</div>

```auto
msg.payload = msg.payload.status.split('</p>') 

```

Read the built in help...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/7948b83d29e14eed8a03712c01adbab73031c203.png)

And always use the great tools Node-RED provides...

> There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.
> 
> Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
> 
> ![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

As for how to split in a JS function - always go look on [mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)

* * *

update...

Forgot to say, the symbol you see in the debug output is a newline character. In JS strings, you type these as `\n` - so you probably would want `msg.payload = msg.payload.status.split('\n') `

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 November 2022 11:16 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/3 "2022-11-24T11:16:55Z")

</div>

You could just use \<pre\>\</pre\> tags around the text, to display it in the text node.  
e.g.

```auto
[{"id":"53063e508fc2d807","type":"inject","z":"452103ea51141731","name":"text with line breaks","props":[{"p":"payload.status","v":"\"text one\\ntext two\\ntext three\\n\"","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":4100,"wires":[["4e323c6454e038e3","449c43256cc9d923"]]},{"id":"4e323c6454e038e3","type":"debug","z":"452103ea51141731","name":"debug 110","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":4040,"wires":[]},{"id":"449c43256cc9d923","type":"ui_text","z":"452103ea51141731","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"name":"","label":"text","format":"<pre>{{msg.payload.status}}</pre>","layout":"row-spread","className":"","x":470,"y":3980,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [24 November 2022 11:25 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/4 "2022-11-24T11:25:31Z")

</div>

That looks the easiest solution as I was just trying to figure out how to display the array the function gives me. Now I came across the next (expected) issue. Its displaying 4 lines out of 6. I thought the text node might be restricted with how many lines it can display. Is there a way to change the height to get more lines in ? This changes all the time, as sometimes I can have 15 or so lines, other times only 1 or 2

I just seen it had been blocked by another text node, it does display more than 4 lines. But it doesnt look right, I think the height of the display field might need adjusting ?

This is from 2 text nodes

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/102c7e890f0eb6c26234c25a5dfab7be93bb220f.png)

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [24 November 2022 12:03 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/5 "2022-11-24T12:03:31Z")

</div>

Playing around with the formatting to get it to display nicely. I can set the colour of the text, but then I have a indent on the first line. No idea where that comes from, its not there if I dont change the colour...  
If I have spacers under the text field, it looks a bit nicer but it seems to center the text (height)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fcc7ebe72fd9e66f8e55d6aa3c0bb729c14053e.png)

I use this in the text node value

`<pre><font color= {{"red"}} > {{msg.payload.status}} </font></pre>`

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 November 2022 12:12 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/6 "2022-11-24T12:12:08Z")

</div>

```auto
<font color="red"><pre>{{msg.payload.status}}</pre></font>

```

Notice no white space between \> and {

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [24 November 2022 12:13 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/7 "2022-11-24T12:13:46Z")

</div>

I did not see that... the indent is now gone

---

<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:** [8 December 2022 12:14 UTC](https://discourse.nodered.org/t/trying-to-split-a-status-text-on-line-break/71168/8 "2022-12-08T12:14:43Z")

</div>

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