# Filter strings and removing text from string

**URL:** <https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637>\
**Category:** General\
**Created:** [28 September 2021 18:05 UTC](https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637 "2021-09-28T18:05:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aabbas](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@aabbas](https://discourse.nodered.org/u/aabbas)\
**Post date:** [28 September 2021 18:05 UTC](https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637/1 "2021-09-28T18:05:39Z")

</div>

Hello everyone,

I get 4 strings from serial in node connected to an arduino:  
string1  
"T1:24,32"  
string2  
"HR1:41,5"  
string3  
"T2:23,58"  
string4  
"HR2:42,2"

First I want to fiter the strings by type (T or HR) **and** by number (1 or 2). For example I just want the T1.

Any help would be greatly appreciated!

![Node red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/344934cb0d5122861a843f128cf9b85a81548dd5.png)

---

<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:** [28 September 2021 18:51 UTC](https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637/2 "2021-09-28T18:51:22Z")

</div>

> [@aabbas](#):
>
> I get 4 strings from serial in node connected to an arduino

Did you write the Arduino code? If so, change it to transmit the name as topic and only put the value in payload.

Edit. Sorry, just read "serial"

So instead, format the data as JSON. Then pass the value through a JSON node and you can access the name and value easily.

---

<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:** [28 September 2021 20:14 UTC](https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637/3 "2021-09-28T20:14:03Z")

</div>

If you can't do that, in a Function node you can do  
`const splits = msg.payload.trim().split(":")`  
The trim will strip the new line off the end and the split will split it into an array. Then `splits[0]` will contain "HR1" and `splits[1]` will contain "50.53"

---

<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:** [27 November 2021 20:14 UTC](https://discourse.nodered.org/t/filter-strings-and-removing-text-from-string/51637/4 "2021-11-27T20:14:16Z")

</div>

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