Remove manuel line break from string for msg.payload and switch

Hello everyone,
I am currently working on a flow and I have now encountered the problem that the "exec" function gives me a string that I cannot process in the switch.

I would like to use the function == in the switch. My problem now is that the string I get from the previous function has a manual line break, which I can't copy into the switch.

I have tried everything possible, but I am just too inexperienced with Node Red and don't know how to make it work.

My approaches:

  • Use Slice in a Function (I couldn't get any output)
  • Switch option "contains" (no difference)

Output exec:
Screenshot 2022-04-05 165412

Switch config:
Screenshot 2022-04-05 165434

You can use a function node to trim the payload before the switch

msg.payload = msg.payload.trim();
return msg;

or use JSONata in the switch property

$trim($$.payload)

2 Likes

Okay wow, that worked perfectly. Thank you very much!

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