# Strip character from text string

**URL:** <https://discourse.nodered.org/t/strip-character-from-text-string/75605>\
**Category:** General\
**Created:** [22 February 2023 19:16 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605 "2023-02-22T19:16:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [22 February 2023 19:16 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/1 "2023-02-22T19:16:30Z")

</div>

I get some data from a sensor that looks like

![2023](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50f6e48279599c1767d45ef3106507659b77106e.jpeg)

I assume the little arrow in the front of the text must be some kind of carriage return? I haven't figured out how to strip that from the payload. That character is always the first but the length of the payload varies  
thanks

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [22 February 2023 19:33 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/2 "2023-02-22T19:33:13Z")

</div>

You can do in a function node

```auto
msg.payload = msg.payload.substring(1)
return msg;

```

This will return the string minus the first character.

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [22 February 2023 19:37 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/3 "2023-02-22T19:37:37Z")

</div>

sorry but the funky character still shows up when I use that in a function

---

<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:** [22 February 2023 19:45 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/4 "2023-02-22T19:45:08Z")

</div>

To remove any whitespace before and after, in a function node use.

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

```

Or in a chnage node and JSONata  
use

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

```

And there is also the contrib string node.

EDIT by @Paul-Reed - correct typo

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [22 February 2023 19:48 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/5 "2023-02-22T19:48:47Z")

</div>

that's the ticket !!  
thanks

---

<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:** [22 February 2023 20:07 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/6 "2023-02-22T20:07:45Z")

</div>

If what you actually want is the number, then you can use  
`msg.payload = Number(msg.payload)`

---

<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:** [8 March 2023 20:08 UTC](https://discourse.nodered.org/t/strip-character-from-text-string/75605/7 "2023-03-08T20:08:14Z")

</div>

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