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

**URL:** <https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835>\
**Category:** General\
**Created:** [5 April 2022 14:57 UTC](https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835 "2022-04-05T14:57:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeonO](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@LeonO](https://discourse.nodered.org/u/LeonO)\
**Post date:** [5 April 2022 14:57 UTC](https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835/1 "2022-04-05T14:57:54Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93b387d7f128766087007e933f9e8c8ca62fc806.png)

Switch config:  
 ![Screenshot 2022-04-05 165434](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57b3744a372d943bd7f662409acaf5ce202c4c95.png)

---

<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:** [5 April 2022 15:00 UTC](https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835/2 "2022-04-05T15:00:49Z")

</div>

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

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

```

or use JSONata in the switch property

```auto
$trim($$.payload)

```

 ![Screenshot_20220405-160340](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91fda4d984215a6174d9936fcb5256bb9f6ce1c8.png)

---

<div class="post-metadata">

**Author:** ![LeonO](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@LeonO](https://discourse.nodered.org/u/LeonO)\
**Post date:** [6 April 2022 13:06 UTC](https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835/3 "2022-04-06T13:06:37Z")

</div>

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

---

<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:** [20 April 2022 13:07 UTC](https://discourse.nodered.org/t/remove-manuel-line-break-from-string-for-msg-payload-and-switch/60835/4 "2022-04-20T13:07:23Z")

</div>

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