# Split to different outputs

**URL:** <https://discourse.nodered.org/t/split-to-different-outputs/5773>\
**Category:** General\
**Created:** [13 December 2018 22:32 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773 "2018-12-13T22:32:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dakure](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dakure](https://discourse.nodered.org/u/dakure)\
**Post date:** [13 December 2018 22:32 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773/1 "2018-12-13T22:32:06Z")

</div>

I am using a split node to tear apart a 8 bit binary number in string with fixed lenght of 1.  
Is there a way to split it in different outputs ?  
Is it possible to use the switch node outputs with the split node to separate them or add outputs in the split node itself?  
Thank you

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 December 2018 00:27 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773/2 "2018-12-14T00:27:02Z")

</div>

Indeed it is possible to use the switch node along with the split node exactly like you described. It is just a matter of configuring both nodes accordingly.

You will want to split your string with a fixed length of one.

![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b7630c528982efb334be7fb69531bd5dcc8af5f2.png)

Then in your switch node you should create as many outputs as required and create the rules to handle the index of the split messages.

 ![r-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/21a9a1e1c268fdbc0d4e3e25bdea9aadac93e2d6.png)

This is how the testing flow looks like (for a binary number of four digits):

 ![r-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b337047691bde927a1421bb757a3db0797b1348a.png)

---

<div class="post-metadata">

**Author:** ![dakure](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dakure](https://discourse.nodered.org/u/dakure)\
**Post date:** [14 December 2018 08:18 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773/3 "2018-12-14T08:18:12Z")

</div>

Thank you so much Andrei,  
The problem is that this only works the first time the number is injected cause the index numbers are incremented in every injection in the split node and they don t show in the outputs anymore.  
Is there a way to have always the same index number or any walkaround?  
Thank you again.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 December 2018 12:01 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773/4 "2018-12-14T12:01:34Z")

</div>

Hi @dakure,

I share the testing flow below. As a matter of fact the value of `msg.parts.index` is "restarted" for each incoming payload (in other words for each injection). Let me know if I am missing something so we can clarify or find an alternative solution.

![r-04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9a83779c1aea98ae86b3474a22da49a3d13b9bd5.png)

```auto
[{"id":"2202b21f.3f4d7e","type":"tab","label":"Split and switch string","disabled":false,"info":""},{"id":"92e26cbf.d1005","type":"split","z":"2202b21f.3f4d7e","name":"","splt":"1","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":140,"wires":[["7e0b01e6.4fe07"]]},{"id":"b156d544.144f08","type":"inject","z":"2202b21f.3f4d7e","name":"","topic":"","payload":"1001","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["92e26cbf.d1005"]]},{"id":"6a2fed9e.1ad054","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":100,"wires":[]},{"id":"7e0b01e6.4fe07","type":"switch","z":"2202b21f.3f4d7e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":410,"y":140,"wires":[["6a2fed9e.1ad054"],["105055c9.5a19ea"],["26c7ab09.eb4054"],["b1e6810f.30e29"]]},{"id":"feba729e.fcdd8","type":"comment","z":"2202b21f.3f4d7e","name":"Split and switch string","info":"Source: https://discourse.nodered.org/t/split-to-different-outputs/5773/2\n","x":140,"y":60,"wires":[]},{"id":"105055c9.5a19ea","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":140,"wires":[]},{"id":"26c7ab09.eb4054","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":180,"wires":[]},{"id":"b1e6810f.30e29","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":220,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![dakure](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dakure](https://discourse.nodered.org/u/dakure)\
**Post date:** [14 December 2018 12:39 UTC](https://discourse.nodered.org/t/split-to-different-outputs/5773/5 "2018-12-14T12:39:05Z")

</div>

You are completely right sorry.  
My mistake was to check the option "Handle as a stream of messages".  
Thank you again 😃
