Removing text from string

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.

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

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

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 :joy:)

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.

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.

1 Like

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