# How to filter a long string that is split

**URL:** <https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737>\
**Category:** General\
**Created:** [6 December 2024 18:03 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737 "2024-12-06T18:03:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 18:03 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/1 "2024-12-06T18:03:14Z")

</div>

I have a string from Brultech GEM that I can split with the & deliminator.  
n=00012915&m=5234702&wh\_1=153454.32&p\_1=3&wh\_2=14839.24&p\_2=20&wh\_3=46336.37&p\_3=0&wh\_4=134758.34&p\_4=11&wh\_5=161041.46&p\_5=0&wh\_6=121477.05&p\_6=197&wh\_7=123890.64&p\_7=0&wh\_8=1695.32&p\_8=0&wh\_9=88036.15&p\_9=68&wh\_10=122949.71&p\_10=64&wh\_11=85653.85&p\_11=0&wh\_12=36438.74&p\_12=0&wh\_13=42235.43&p\_13=1&wh\_14=134104.41&p\_14=114&wh\_15=138359.79&p\_15=8&wh\_16=128390.08&p\_16=2&wh\_17=67164.58&p\_17=0&wh\_18=156724.70&p\_18=8&wh\_19=43067.42&p\_19=3&wh\_20=27711.98&p\_20=3&wh\_21=41503.41&p\_21=192&wh\_22=103937.92&p\_22=0&wh\_23=149379.56&p\_23=2&wh\_24=125592.45&p\_24=166&wh\_25=50748.13&p\_25=85&wh\_26=20449.79&p\_26=1&wh\_27=20676.12&p\_27=4&wh\_28=11427.20&p\_28=0&wh\_29=33011.10&p\_29=0&wh\_30=94501.75&p\_30=0&wh\_31=97257.79&p\_31=114&wh\_32=18965.52&p\_32=0&v=123.8

I only want the item (P\_24=) and its value. I can split this into individual substrings, but I can not figure out how to filter only the P\_24 value.  
Any help would be appreciated.

---

<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:** [6 December 2024 18:21 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/2 "2024-12-06T18:21:21Z")

</div>

Simple after the split use a switch node like this:  
 ![Screenshot 2024-12-06 at 1.20.28 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/optimized/3X/4/3/43a91d9821f2b335ee756b3d17ac08ee97bbee25_2_690x65.png)

Here is the flow

```auto
[{"id":"453ffebef9cf238f","type":"inject","z":"05a89d30924df06f","name":"sample data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"n=00012915&m=5234702&wh_1=153454.32&p_1=3&wh_2=14839.24&p_2=20&wh_3=46336.37&p_3=0&wh_4=134758.34&p_4=11&wh_5=161041.46&p_5=0&wh_6=121477.05&p_6=197&wh_7=123890.64&p_7=0&wh_8=1695.32&p_8=0&wh_9=88036.15&p_9=68&wh_10=122949.71&p_10=64&wh_11=85653.85&p_11=0&wh_12=36438.74&p_12=0&wh_13=42235.43&p_13=1&wh_14=134104.41&p_14=114&wh_15=138359.79&p_15=8&wh_16=128390.08&p_16=2&wh_17=67164.58&p_17=0&wh_18=156724.70&p_18=8&wh_19=43067.42&p_19=3&wh_20=27711.98&p_20=3&wh_21=41503.41&p_21=192&wh_22=103937.92&p_22=0&wh_23=149379.56&p_23=2&wh_24=125592.45&p_24=166&wh_25=50748.13&p_25=85&wh_26=20449.79&p_26=1&wh_27=20676.12&p_27=4&wh_28=11427.20&p_28=0&wh_29=33011.10&p_29=0&wh_30=94501.75&p_30=0&wh_31=97257.79&p_31=114&wh_32=18965.52&p_32=0&v=123.8","payloadType":"str","x":250,"y":120,"wires":[["8df98d0763a8cc3e"]]},{"id":"8df98d0763a8cc3e","type":"split","z":"05a89d30924df06f","name":"Split using &","splt":"&","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":430,"y":120,"wires":[["064f28617445342b"]]},{"id":"064f28617445342b","type":"switch","z":"05a89d30924df06f","name":"dose it contain p=24","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"p_24","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":120,"wires":[["b4505c2a3f08a110"]]},{"id":"b4505c2a3f08a110","type":"debug","z":"05a89d30924df06f","name":"debug 3526","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":120,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 18:37 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/3 "2024-12-06T18:37:03Z")

</div>

Thank You, It works. I have tried that same option and it did not work for me. Maybe because I was splitting the string in the tcp in node? I dont know, but this works, Thank You!  
edit: I think I was using a capital P instead of a small p in the switch node.

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 18:42 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/4 "2024-12-06T18:42:10Z")

</div>

If you could help me with one more step? All I need is the value so to change the P\_24= (value) to a json {"value":()}So my automation system (Homeseer) can read the value.  
Thanks again.

---

<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:** [6 December 2024 18:50 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/5 "2024-12-06T18:50:32Z")

</div>

So add another `split` node and split it at the `=` then use a change node to build what you want it to look like

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 19:07 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/6 "2024-12-06T19:07:10Z")

</div>

Great, but how to change a changing variable, The P\_24 stays the same but the value always changes. So in the change node I Search for ? as it always changes value.

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 19:09 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/7 "2024-12-06T19:09:04Z")

</div>

This is all new to me, as that is probably obvious.

---

<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:** [6 December 2024 19:11 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/8 "2024-12-06T19:11:33Z")

</div>

In a change node  
select change  
search for `P_24=`  
replace with `blank value`

If this is all new to you, you may benefit from watching the [essentials videos](https://m.youtube.com/watch?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&v=ksGeUD26Mw0&embeds_referring_euri=https%3A%2F%2Fnodered.org%2F&source_ve_path=OTY3MTQ&feature=emb_imp_woyt).

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 19:25 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/9 "2024-12-06T19:25:33Z")

</div>

Thanks, This will remove the p\_24 and change to "", but I need the value and how do you search for a changing string item (value of p\_24)

---

<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:** [6 December 2024 19:50 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/10 "2024-12-06T19:50:24Z")

</div>

> [@KSO760](#):
>
> how do you search for a changing string item (value of p\_24)

you use

> [@zenofmud](#):
>
> Here is the flow
> 
> ```auto
> [{"id":"453ffebef9cf238f","type":"inject","z":"05a89d30924df06f","name":"sample data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"n=00012915&m=5234702&wh_1=153454.32&p_1=3&wh_2=14839.24&p_2=20&wh_3=46336.37&p_3=0&wh_4=134758.34&p_4=11&wh_5=161041.46&p_5=0&wh_6=121477.05&p_6=197&wh_7=123890.64&p_7=0&wh_8=1695.32&p_8=0&wh_9=88036.15&p_9=68&wh_10=122949.71&p_10=64&wh_11=85653.85&p_11=0&wh_12=36438.74&p_12=0&wh_13=42235.43&p_13=1&wh_14=134104.41&p_14=114&wh_15=138359.79&p_15=8&wh_16=128390.08&p_16=2&wh_17=67164.58&p_17=0&wh_18=156724.70&p_18=8&wh_19=43067.42&p_19=3&wh_20=27711.98&p_20=3&wh_21=41503.41&p_21=192&wh_22=103937.92&p_22=0&wh_23=149379.56&p_23=2&wh_24=125592.45&p_24=166&wh_25=50748.13&p_25=85&wh_26=20449.79&p_26=1&wh_27=20676.12&p_27=4&wh_28=11427.20&p_28=0&wh_29=33011.10&p_29=0&wh_30=94501.75&p_30=0&wh_31=97257.79&p_31=114&wh_32=18965.52&p_32=0&v=123.8","payloadType":"str","x":250,"y":120,"wires":[["8df98d0763a8cc3e"]]},{"id":"8df98d0763a8cc3e","type":"split","z":"05a89d30924df06f","name":"Split using &","splt":"&","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":430,"y":120,"wires":[["064f28617445342b"]]},{"id":"064f28617445342b","type":"switch","z":"05a89d30924df06f","name":"dose it contain p=24","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"p_24","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":120,"wires":[["b4505c2a3f08a110"]]},{"id":"b4505c2a3f08a110","type":"debug","z":"05a89d30924df06f","name":"debug 3526","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":120,"wires":[]}]
> 
> ```

Then you remove the p\_24= as shown using a change node.

You then have the changing value in th msg.payload message property.

---

<div class="post-metadata">

**Author:** ![KSO760](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kso760/32/96961_2.png) [@KSO760](https://discourse.nodered.org/u/KSO760)\
**Post date:** [6 December 2024 20:34 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/11 "2024-12-06T20:34:15Z")

</div>

> [@zenofmud](#):
>
> ```auto
> [{"id":"453ffebef9cf238f","type":"inject","z":"05a89d30924df06f","name":"sample data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"n=00012915&m=5234702&wh_1=153454.32&p_1=3&wh_2=14839.24&p_2=20&wh_3=46336.37&p_3=0&wh_4=134758.34&p_4=11&wh_5=161041.46&p_5=0&wh_6=121477.05&p_6=197&wh_7=123890.64&p_7=0&wh_8=1695.32&p_8=0&wh_9=88036.15&p_9=68&wh_10=122949.71&p_10=64&wh_11=85653.85&p_11=0&wh_12=36438.74&p_12=0&wh_13=42235.43&p_13=1&wh_14=134104.41&p_14=114&wh_15=138359.79&p_15=8&wh_16=128390.08&p_16=2&wh_17=67164.58&p_17=0&wh_18=156724.70&p_18=8&wh_19=43067.42&p_19=3&wh_20=27711.98&p_20=3&wh_21=41503.41&p_21=192&wh_22=103937.92&p_22=0&wh_23=149379.56&p_23=2&wh_24=125592.45&p_24=166&wh_25=50748.13&p_25=85&wh_26=20449.79&p_26=1&wh_27=20676.12&p_27=4&wh_28=11427.20&p_28=0&wh_29=33011.10&p_29=0&wh_30=94501.75&p_30=0&wh_31=97257.79&p_31=114&wh_32=18965.52&p_32=0&v=123.8","payloadType":"str","x":250,"y":120,"wires":[["8df98d0763a8cc3e"]]},{"id":"8df98d0763a8cc3e","type":"split","z":"05a89d30924df06f","name":"Split using &","splt":"&","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":430,"y":120,"wires":[["064f28617445342b"]]},{"id":"064f28617445342b","type":"switch","z":"05a89d30924df06f","name":"dose it contain p=24","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"p_24","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":120,"wires":[["b4505c2a3f08a110"]]},{"id":"b4505c2a3f08a110","type":"debug","z":"05a89d30924df06f","name":"debug 3526","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":120,"wires":[]}]
> 
> ```

Thank You for your help.

---

<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:** [6 March 2025 20:34 UTC](https://discourse.nodered.org/t/how-to-filter-a-long-string-that-is-split/93737/12 "2025-03-06T20:34:44Z")

</div>

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