# Splitting string into different values

**URL:** <https://discourse.nodered.org/t/splitting-string-into-different-values/33766>\
**Category:** General\
**Created:** [5 October 2020 12:25 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766 "2020-10-05T12:25:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DdP13](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DdP13](https://discourse.nodered.org/u/DdP13)\
**Post date:** [5 October 2020 12:25 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766/1 "2020-10-05T12:25:30Z")

</div>

Hi i want to split these values

msg.payload : string[27]

"RELAY-STATE-255,0,0,0,0,OK" the 4 zeros represent each a decimal number from 0-255. i want to isolate these 4 zeros . i managed this with $substring(payload, -9, 1 ) for example . but if the zero becomes lets say a 16 this method does not work .

not a programmer . just trying to seperate these values to set my relays in proper status

---

<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:** [5 October 2020 12:33 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766/2 "2020-10-05T12:33:13Z")

</div>

add a function node with this code in...

```auto
var str = msg.payload;
var parts = str.split(",");
msg.payload = {
  name: parts[0],
  item1: parseInt(parts[1]),
  item2: parseInt(parts[2]),
  item3: parseInt(parts[3]),
  item4: parseInt(parts[4]),
  status: parts[5],
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![DdP13](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DdP13](https://discourse.nodered.org/u/DdP13)\
**Post date:** [5 October 2020 13:03 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766/3 "2020-10-05T13:03:52Z")

</div>

great ,

the fact its spitting out an error i just ignore it. this is what i get when putting in your code:

5-10-2020 14:59:45[node: 2386070d.67c548](http://192.168.2.242:8123/api/hassio_ingress/-EIhRhoBbDzjM0krpGGetGb3D26IkjabVIo_K--L6EQ/#)msg : string[41]

"Input is not a number or parsable string."

5-10-2020 14:59:45[node: f736b0a8.0a9fc](http://192.168.2.242:8123/api/hassio_ingress/-EIhRhoBbDzjM0krpGGetGb3D26IkjabVIo_K--L6EQ/#)msg.payload : Object

object

name: "RELAY-STATE-255"

item1: 0

item2: 0

item3: 0

item4: 1

status: "OK"

now the matter of fact is getting the items sepratly 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 October 2020 13:17 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766/4 "2020-10-05T13:17:04Z")

</div>

> [@DdP13](#):
>
> 5-10-2020 14:59:45[node: 2386070d.67c548](http://192.168.2.242:8123/api/hassio_ingress/-EIhRhoBbDzjM0krpGGetGb3D26IkjabVIo_K--L6EQ/#)msg : string[41]
> 
> "Input is not a number or parsable string."

That is coming from a different node, note the id number at the top. If you click on that it should highlight the node.

To understand how to use the message properties read the node-red docs page Working with Messages.

---

<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:** [4 December 2020 13:17 UTC](https://discourse.nodered.org/t/splitting-string-into-different-values/33766/5 "2020-12-04T13:17:17Z")

</div>

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