# Unable to remove return carriage from msg

**URL:** <https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392>\
**Category:** General\
**Created:** [28 May 2021 07:26 UTC](https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392 "2021-05-28T07:26:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [28 May 2021 07:26 UTC](https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392/1 "2021-05-28T07:26:56Z")

</div>

I am receiving a simple msg from a Python code controlling a temperature sensor.  
The Python output is stable and doesn't show any carriage return/new line or spaces  
I have set a function trying to remove the carriage return but despite many attempts I am failing.  
I wonder from where the carriage return is coming, however I would be happy to just remove it.  
The function I am using is the following:

```auto
var t=msg.payload
t = t.replace(/[\n\r]/g, '')
if(t.length>1)
    return msg

```

```auto
[{"id":"3d0da9a4.5c5796","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"861cf5c7.a8bad8","type":"debug","z":"3d0da9a4.5c5796","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"4404f2f3.bf361c","type":"exec","z":"3d0da9a4.5c5796","command":" bash /home/pi/Develop/Temp/Temperature.sh","addpay":"","append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Command Temperature","x":310,"y":200,"wires":[["e8ed8456.02d768"],[],[]]},{"id":"e8ed8456.02d768","type":"function","z":"3d0da9a4.5c5796","name":"","func":"var t=msg.payload\nt = t.replace(/[\\n\\r]/g, '')\nif(t.length>1)\n return msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":200,"wires":[["6db2d583.4a37fc","861cf5c7.a8bad8"]]},{"id":"6db2d583.4a37fc","type":"influxdb out","z":"3d0da9a4.5c5796","influxdb":"b87cafc6.11924","name":"Digi-Influx","measurement":"temperature","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":720,"y":220,"wires":[]},{"id":"908d862c.149d08","type":"inject","z":"3d0da9a4.5c5796","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":120,"wires":[["4404f2f3.bf361c"]]},{"id":"b87cafc6.11924","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"datastorage","name":"","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true}]

```

the output I am getting is like this:

 ![Schermata 2021-05-28 alle 09.25.00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0501d88b68ad28a271374809b82df85840280df.jpeg)  
Which is causing empty row of data in influx.  
Any idea about how to remove the carriage return?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2021 07:31 UTC](https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392/2 "2021-05-28T07:31:24Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [28 May 2021 08:18 UTC](https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392/3 "2021-05-28T08:18:06Z")

</div>

For some reason when I tried that at the beginning, it didn't work.  
But now it is working and the issue is solved.  
Thanks a million

---

<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:** [11 June 2021 08:18 UTC](https://discourse.nodered.org/t/unable-to-remove-return-carriage-from-msg/46392/4 "2021-06-11T08:18:50Z")

</div>

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