# String handling remove newline

**URL:** <https://discourse.nodered.org/t/string-handling-remove-newline/74620>\
**Category:** General\
**Created:** [2 February 2023 18:05 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620 "2023-02-02T18:05:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspv](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@jspv](https://discourse.nodered.org/u/jspv)\
**Post date:** [2 February 2023 18:05 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/1 "2023-02-02T18:05:08Z")

</div>

I am getting out of an exec mode: msg.payload : string[11]  
"2498101658↵"

but what I need is: msg.payload : string[10]  
"2498101658"

I have tried the string mode without success.

---

<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:** [2 February 2023 18:07 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/2 "2023-02-02T18:07:41Z")

</div>

In a function node

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

```

or in a change node  
set `msg.` `payload`  
to JSONata `$trim($$.payload)`

---

<div class="post-metadata">

**Author:** ![jspv](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@jspv](https://discourse.nodered.org/u/jspv)\
**Post date:** [2 February 2023 18:15 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/3 "2023-02-02T18:15:54Z")

</div>

Thanks,  
worked straightaway.  
I've learned something.

---

<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:** [2 February 2023 18:30 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/4 "2023-02-02T18:30:27Z")

</div>

A better title for your topic maybe `String handling remove newline` It would help future readers find the solution to a similar issue, `String handling` is fairly broad.

---

<div class="post-metadata">

**Author:** ![paulkeates](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@paulkeates](https://discourse.nodered.org/u/paulkeates)\
**Post date:** [3 February 2023 13:41 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/5 "2023-02-03T13:41:07Z")

</div>

Hi,

There is also the " node-red-contrib-string" node if you need to do more-advanced string handling and want to do it in a 'visual' way.

Cheers,

Paul

---

<div class="post-metadata">

**Author:** ![jspv](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@jspv](https://discourse.nodered.org/u/jspv)\
**Post date:** [5 February 2023 21:54 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/6 "2023-02-05T21:54:56Z")

</div>

I did look into every one of the " node-red-contrib-string" methods, including trim right, but did not find any which would remove the return character.  
As you suggest, I prefer to do it in a 'visual' way: this is preferable when sharing a flow with somebody who is not familiar with functions or Jsonata.  
In order to obtain the string the exec node runs a python script in which I had added a marker word at the end of the string. That done the exec node adds the return character after the marker and I could thereafter remove both marker and return sign with a " node-red-contrib-string".  
Somehow messy and leading me to post my question.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 February 2023 22:29 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/7 "2023-02-05T22:29:31Z")

</div>

The JavaScript trim() function will remove a newline from the end of a string.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [5 February 2023 22:41 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/8 "2023-02-05T22:41:43Z")

</div>

> [@E1cid](#):
>
> A better title for your topic maybe `String handling remove newline` It would help future readers find the solution to a similar issue,

Agree, topic title renamed.

---

<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:** [19 February 2023 22:41 UTC](https://discourse.nodered.org/t/string-handling-remove-newline/74620/9 "2023-02-19T22:41:44Z")

</div>

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