# Function to cut text message

**URL:** <https://discourse.nodered.org/t/function-to-cut-text-message/70398>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 November 2022 13:02 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398 "2022-11-10T13:02:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gideon](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gideon](https://discourse.nodered.org/u/gideon)\
**Post date:** [10 November 2022 13:02 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/1 "2022-11-10T13:02:46Z")

</div>

Hello everyone.

On the Raspberry Pi I connect to the USB input a module that has 8 A/D inputs.  
The module sends to the serial port every 500 MS the reading of 8 channels in analog input.  
I need a function that will filter the channel I use let's say ch1  
Which function will do this?  
this is a sample reading "  
"CH1: 2004 \> 1.645V"  
"CH2: 2134 \> 0.640V"  
"CH3: 2304 \> 1.145V"  
''  
"CH8: 3304 \> 1.005V"

I need to send just the "CH2: 0.640V"  
thanks

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 November 2022 13:43 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/2 "2022-11-10T13:43:46Z")

</div>

Are these seperate msg's? If so, and if the string is in msg.payload, you could use a `switch` node to use the 'contains' option and compare it to the channel number you want to pass thru, like 'CH2'

---

<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:** [10 November 2022 15:48 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/3 "2022-11-10T15:48:25Z")

</div>

Are you sure you want a string  
`"CH2: 0.640V"`  
and not a javascript object  
`{CH2: 0.64}`  
which, if it was in msg.payload, would allow you to use `msg.payload.CH2` to access the value 0.64

---

<div class="post-metadata">

**Author:** ![gideon](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gideon](https://discourse.nodered.org/u/gideon)\
**Post date:** [10 November 2022 16:43 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/4 "2022-11-10T16:43:37Z")

</div>

The module send every 500msec the all 8 analog value of his input at once message.  
With using Switch I thing I can’t do it

---

<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:** [10 November 2022 16:49 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/5 "2022-11-10T16:49:56Z")

</div>

How have you configured the serial port? Try setting it to split on `\n` and it may give you separate messages. If that doesn't work feed the message into a debug node and show us what it looks like.

---

<div class="post-metadata">

**Author:** ![gideon](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gideon](https://discourse.nodered.org/u/gideon)\
**Post date:** [10 November 2022 20:05 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/6 "2022-11-10T20:05:29Z")

</div>

Thanks I will try it tomorrow and will report about it

---

<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:** [9 January 2023 20:06 UTC](https://discourse.nodered.org/t/function-to-cut-text-message/70398/7 "2023-01-09T20:06:21Z")

</div>

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