# Removing text from string

**URL:** <https://discourse.nodered.org/t/removing-text-from-string/5626>\
**Category:** General\
**Created:** [9 December 2018 23:15 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626 "2018-12-09T23:15:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mason08](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mason08](https://discourse.nodered.org/u/mason08)\
**Post date:** [9 December 2018 23:15 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/1 "2018-12-09T23:15:48Z")

</div>

Im trying to remove text from a string before sending it to a function node to then be converted over to a number. How would i do that? Im receiving data on serial from arduino and running that through a switch node. The string has text and then a number. The node im using to convert to a number doesnt like the text being in the string.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 December 2018 23:33 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/2 "2018-12-09T23:33:23Z")

</div>

Hi @mason08, it would be much easier if you provided an example of the text you have.

---

<div class="post-metadata">

**Author:** ![mason08](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mason08](https://discourse.nodered.org/u/mason08)\
**Post date:** [10 December 2018 00:33 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/3 "2018-12-10T00:33:53Z")

</div>

Both sensors come through with text then value. Example, "FLUE 124"  
flue 124 is the payload

---

<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 December 2018 01:15 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/4 "2018-12-10T01:15:42Z")

</div>

If they both are string/space/number there are several ways you could do this

1. use a split function and split it on the space. Then you will get two msgs out of the split. drop the first and convert the second to a number to use
2. you could use a function node to do the same thing
3. get fancy and use a change node and the jsonata expression `$number($split(payload, " ")[1])` which in english says 'convert to a number the second part of the array created by spliting the men.payload on a space" (see doesn't that make it clear 😂)

---

<div class="post-metadata">

**Author:** ![mason08](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mason08](https://discourse.nodered.org/u/mason08)\
**Post date:** [10 December 2018 02:53 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/5 "2018-12-10T02:53:29Z")

</div>

I ended up using a switch to sort and then a change to clean it up. Thanks for the help. Now onto the next project.

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [10 December 2018 04:01 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/6 "2018-12-10T04:01:03Z")

</div>

[Node-red-contrib-string](https://www.npmjs.com/package/node-red-contrib-string) would be a good fit for this sort of thing if you're feeling lazy. It's my favorite crutch for proof of concept flows before I hand them off to other maintainers at work.

---

<div class="post-metadata">

**Author:** ![mason08](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mason08](https://discourse.nodered.org/u/mason08)\
**Post date:** [10 December 2018 21:28 UTC](https://discourse.nodered.org/t/removing-text-from-string/5626/7 "2018-12-10T21:28:18Z")

</div>

Isnt that string node basically the same thing im using my change node for?
