# Splitting a msg line with Split or Function?

**URL:** https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636
**Category:** General
**Created:** [31 March 2019 15:49 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636 "2019-03-31T15:49:06Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Observatory\_Gromme](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Observatory\_Gromme](https://discourse.nodered.org/u/Observatory_Gromme)
#### Post date: [31 March 2019 15:49 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/1 "2019-03-31T15:49:06Z")

</div>

Dear,

Okey, so, i'm very new to programming at all. I am an Amateur Astronomer with building an automated equipment station. Now i'm also trying to use node-RED and dashboard to use it for many control situations, like the wheater, controlling relays etc etc.

Okay: my question: I have a file on the computer witch contains only one line like this and will updated every 10 seconds:  
2019-03-24 21:41:57.00 C K -26.4 7.6 7.6 3.0 59 0.1 54 0 0 00000 043548.90413 1 1 1 1 0 0

As you can see, the readings are separated by a space. The numbers are on fixed places, so they will not move in an other row. Now i want to separate the readings in to each value as an output, so i can put a dashboard tool to it, like a graph, gauge, charts, a temperature reading, wind speed etc etc.

I managed to use the split function and let it split on a "space", and this works, i can get every reading in separated messages in the debug folder. But how can i use the separated messages? Or should i do it in an other way

this is the code i use now:

[{"id":"67191ebb.438f9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3fc0f848.0f0178","type":"inject","z":"67191ebb.438f9","name":"","topic":"test","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":147,"y":98,"wires":[["ba790031.6b9f1"]]},{"id":"a181722c.fefd4","type":"debug","z":"67191ebb.438f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1057,"y":125,"wires":},{"id":"ba790031.6b9f1","type":"file in","z":"67191ebb.438f9","name":"","filename":"/home/pi/Documents/test","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":515,"y":99,"wires":[["b005500c.28398"]]},{"id":"b005500c.28398","type":"split","z":"67191ebb.438f9","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":773,"y":106,"wires":[["a181722c.fefd4"]]}]

Any help is welcome. Thank you.

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [31 March 2019 16:12 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/2 "2019-03-31T16:12:31Z")

</div>

If you put a join node after the split node set to array you will have an array of individual values so you can reference them by index.

```auto
[{"id":"6e423ebd.a6bbc","type":"inject","z":"1d66267b.4c5caa","name":"","topic":"","payload":"2019-03-24 21:41:57.00 C K -26.4 7.6 7.6 3.0 59 0.1 54 0 0 00000 043548.90413 1 1 1 1 0 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["cb42b469.b403d8"]]},{"id":"cb42b469.b403d8","type":"split","z":"1d66267b.4c5caa","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":100,"wires":[["b8dc29d2.24faf8"]]},{"id":"623e7c19.713154","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":160,"wires":[]},{"id":"b8dc29d2.24faf8","type":"join","z":"1d66267b.4c5caa","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":120,"wires":[["623e7c19.713154"]]}]

```

---

<div class="post-metadata">

### Author: ![Observatory\_Gromme](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Observatory\_Gromme](https://discourse.nodered.org/u/Observatory_Gromme)
#### Post date: [31 March 2019 16:46 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/3 "2019-03-31T16:46:43Z")

</div>

Wow, this is a great answer! Indeed what i was looking for! Now, how do i do the reference by index? 🙂 , As you can see, i'm no programmer at all unfortunately...

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [31 March 2019 16:50 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/4 "2019-03-31T16:50:05Z")

</div>

payload[0] is the date  
payload[1] is the time  
You get the idea?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [31 March 2019 16:55 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/5 "2019-03-31T16:55:55Z")

</div>

Also read the page in the docs about working with messages which will show you how to use tool tips in the debug to find out the correct path

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [31 March 2019 20:26 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/6 "2019-03-31T20:26:52Z")

</div>

The CSV node may be a better choice in the first place. It can be set to split on space, instead of the default comma, and the "template" line lets you assign the property names to each column so the resulting object is easier to work with.... eg msg.payload.date and so on.

---

<div class="post-metadata">

### Author: ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)
#### Post date: [1 April 2019 03:59 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/7 "2019-04-01T03:59:49Z")

</div>

> [@Observatory\_Gromme](#):
>
> Okey, so, i'm very new to programming at all. I am an Amateur Astronomer with building an automated equipment station. Now i'm also trying to use node-RED and dashboard to use it for many control situations, like the wheater, controlling relays etc etc.

Was only thinking of this yesterday. 😁

Are you going to attempt to interface with the ASCOM api? ([https://ascom-standards.org/](https://ascom-standards.org/))

---

<div class="post-metadata">

### Author: ![Observatory\_Gromme](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Observatory\_Gromme](https://discourse.nodered.org/u/Observatory_Gromme)
#### Post date: [1 April 2019 04:59 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/8 "2019-04-01T04:59:10Z")

</div>

Maybe in the future. But like said, no programming skills, so just need to learn that first... 😄

---

<div class="post-metadata">

### Author: ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)
#### Post date: [2 April 2019 05:54 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/9 "2019-04-02T05:54:30Z")

</div>

Reason why I asked is that if you just developed a "bridge" (node or set of nodes) between NR and ASCOM then bingo 🤠 You would then have access to all the ASCOM developed interfaces, as opposed to inventing what would effectively be a new "api".

Just a thought.

---

<div class="post-metadata">

### Author: ![Observatory\_Gromme](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Observatory\_Gromme](https://discourse.nodered.org/u/Observatory_Gromme)
#### Post date: [3 April 2019 06:15 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/10 "2019-04-03T06:15:35Z")

</div>

Dear,

Thank you for your thoughts. Well , like said, i'm really no programmer at all. My equipment itself would be run through ASCOM with build software. But for learning i thought: Node-RED should not be that hard... 🙂, any way.

I now use the CSV node, and indeed i get it by Col1 - 19. So then inserting a template node, and in the command line rename the payloads? right?  
Can someone maybe please show me one line for instance col 1, witch is the date, how i assign a property name to it? I will also read the manuals like "ukmoose" said.

Have a nice day!

---

<div class="post-metadata">

### Author: ![crativ2000](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@crativ2000](https://discourse.nodered.org/u/crativ2000)
#### Post date: [13 January 2022 22:40 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/11 "2022-01-13T22:40:36Z")

</div>

Hello-  
Would any participant in this conversation please, help us with this?

> [@Implementing virtual Serial port communication: java with node-red (The Figures are attached in subsequent postings)](https://discourse.nodered.org/t/implementing-virtual-serial-port-communication-java-with-node-red-the-figures-are-attached-in-subsequent-postings/56278/24):
>
> Using SPLIT to separate two parts of a message, so we can send only one part to a PLC How can we use the Split function to separate the two parts of a message so that we can send only one part of the message to a PLC? Our project has a total of 18 variables. Each variable must have a different value. My GUI must identify each variable, extract its corresponding value from the created GUI, and send it to a PLC. Here we share part of the code for 4 of the 18 variables. if (msg.payload == 1) { …

Best regards

---

<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: [13 January 2022 23:43 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/12 "2022-01-13T23:43:58Z")

</div>

@crativ2000 why are you posting on this 3 year old thread when you have not replied to my message posted 5 hours ago?

> [@Implementing virtual Serial port communication: java with node-red (The Figures are attached in subsequent postings)](https://discourse.nodered.org/t/implementing-virtual-serial-port-communication-java-with-node-red-the-figures-are-attached-in-subsequent-postings/56278/26):
>
> It seems you (or your team) are developing this Java app. Why don't you send JSON instead of custom strings joined by &? You would have solved this days ago. No string splitting, data values & topics available with zero effort. Do you understand what the benefit of sending JSON offers? Do you understand what JSON is? Lastly, if you absolutely MUST use this custom strings format, please show me 2 demo strings and how they should look after the function node. E.g. xyz&124 should send { "topi…

---

<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: [14 January 2022 15:05 UTC](https://discourse.nodered.org/t/splitting-a-msg-line-with-split-or-function/9636/13 "2022-01-14T15:05:38Z")

</div>


