String handling remove newline

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

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

I have tried the string mode without success.

In a function node

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

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

worked straightaway.
I've learned something.

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.

1 Like


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.



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.

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

Agree, topic title renamed.

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