# Extracted from a part of a chain

**URL:** <https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [12 December 2021 16:25 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082 "2021-12-12T16:25:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manu110](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Manu110](https://discourse.nodered.org/u/Manu110)\
**Post date:** [12 December 2021 16:25 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/1 "2021-12-12T16:25:06Z")

</div>

Hello.  
I am starting with nodeRed.  
I am looking for how it can be extracted from a part of a chain,  
I expose the message that is received. "C, \*, 1234, Z". I want to get the value '1234'.  
How should I do it in a function?  
Where can I find documentation for working with strings in NODERED?  
Thanks and regards.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [12 December 2021 16:30 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/2 "2021-12-12T16:30:15Z")

</div>

One method would be to use the csv parser node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c91a22549c1e40ecbe1a2947735a2c2fb745d20.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5cecb4d0f2c61fb525c54619f5e7d0279b54cab6.png)

and then pick out the 3rd item in the resulting array

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28516763b8f4f28861485eecd77347fa66f59d37.png)

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [12 December 2021 16:32 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/3 "2021-12-12T16:32:47Z")

</div>

Why are all of you want to extract somehting with a function node - writing code. Node Red has its strength by using nodes:

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

```auto
[{"id":"7f8eb7fe4b3bf817","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C, *, 1234, Z","payloadType":"str","x":690,"y":580,"wires":[["e7bbf036233cfeed"]]},{"id":"e7bbf036233cfeed","type":"split","z":"cb05e14b.326a9","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":870,"y":580,"wires":[["1bc94331a3c6cc17"]]},{"id":"93be156fa87a1d48","type":"debug","z":"cb05e14b.326a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1190,"y":580,"wires":[]},{"id":"1bc94331a3c6cc17","type":"switch","z":"cb05e14b.326a9","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1020,"y":580,"wires":[["93be156fa87a1d48"]]}]

```

---

<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:** [12 December 2021 16:54 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/4 "2021-12-12T16:54:36Z")

</div>

Because it simpler and allows to trim or convert to a number etc if needed and It is often quicker than sending 4 messages when one will do.  
@Manu110 here ar examples of using [Javascript](https://www.w3schools.com/js/js_string_methods.asp) and [JSONata](https://docs.jsonata.org/overview.html) for the OP

```auto
[{"id":"d3712560.b7de8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C, *, 1234, Z","payloadType":"str","x":160,"y":1160,"wires":[["65da86a0.e11e08"]]},{"id":"65da86a0.e11e08","type":"function","z":"c791cbc0.84f648","name":"","func":"msg.payload = msg.payload.split(\",\")[2].trim()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":1160,"wires":[["98730897.18ec28"]]},{"id":"98730897.18ec28","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":1160,"wires":[]},{"id":"7f8eb7fe4b3bf817","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C, *, 1234, Z","payloadType":"str","x":160,"y":1060,"wires":[["cd5bff6.e8a8d"]]},{"id":"cd5bff6.e8a8d","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim($split($$.payload,\",\")[2])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":1060,"wires":[["93be156fa87a1d48"]]},{"id":"93be156fa87a1d48","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":1060,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [12 December 2021 16:58 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/5 "2021-12-12T16:58:49Z")

</div>

Ok then we can code all our flows in one function node and then only in-Nodes and out-Nodes messages will be sent. 😉

---

<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:** [12 December 2021 17:04 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/6 "2021-12-12T17:04:34Z")

</div>

If you don't want to use function and code that's fine. P.s. Your flow results in 4 times the number of messages sent and still you have not parsed the "1234" correctly.

@cymplecy I like your thought. You could also target the specific string as below

 ![Screenshot_20211212-170220](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2daee84dc63f3f9a42ea2fd17074f0e555c7d413.png)

---

<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:** [26 December 2021 17:04 UTC](https://discourse.nodered.org/t/extracted-from-a-part-of-a-chain/55082/7 "2021-12-26T17:04:51Z")

</div>

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